mirror of
https://github.com/sbrl/powahroot.git
synced 2024-11-22 06:23:02 +00:00
Reafctor README
This commit is contained in:
parent
e543c59e78
commit
c162054bea
1 changed files with 10 additions and 9 deletions
19
README.md
19
README.md
|
@ -17,15 +17,8 @@ Install powahroot as a dependency with npm:
|
||||||
npm install --save powahroot
|
npm install --save powahroot
|
||||||
```
|
```
|
||||||
|
|
||||||
Then `import` the router you're after:
|
If your build process supports [tree-shaking](https://webpack.js.org/guides/tree-shaking/), only the router(s?) you need will be included in the final output of your build - as _powahroot_ uses ES6 modules.
|
||||||
|
|
||||||
```js
|
|
||||||
import { ServerRouter } from 'powahroot';
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
import { ClientRouter } from 'powahroot';
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -43,6 +36,10 @@ Syntax | Meaning
|
||||||
Initialise a new router like this:
|
Initialise a new router like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ClientRouter } from 'powahroot';
|
||||||
|
|
||||||
|
// ....
|
||||||
|
|
||||||
const router = new ClientRouter({
|
const router = new ClientRouter({
|
||||||
// Options object. Default settings:
|
// Options object. Default settings:
|
||||||
verbose: false, // Whether to be verbose in console.log() messages
|
verbose: false, // Whether to be verbose in console.log() messages
|
||||||
|
@ -54,6 +51,10 @@ const router = new ClientRouter({
|
||||||
The server router works slightly differently, to account for the different environment it's designed for. Here's how to use it:
|
The server router works slightly differently, to account for the different environment it's designed for. Here's how to use it:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ServerRouter } from 'powahroot';
|
||||||
|
|
||||||
|
// ....
|
||||||
|
|
||||||
const router = new ServerRouter();
|
const router = new ServerRouter();
|
||||||
router.on_all(async (context, next) => { console.debug(context.url); await next()})
|
router.on_all(async (context, next) => { console.debug(context.url); await next()})
|
||||||
router.get("/files/::filepath", (context, _next) => context.send.plain(200, `You requested ${context.params.filepath}`));
|
router.get("/files/::filepath", (context, _next) => context.send.plain(200, `You requested ${context.params.filepath}`));
|
||||||
|
@ -62,7 +63,7 @@ router.get("/files/::filepath", (context, _next) => context.send.plain(200, `You
|
||||||
|
|
||||||
The `context` argument there is of type `RouterContext`. Check out the API reference (link below) to learn about the other useful properties it has.
|
The `context` argument there is of type `RouterContext`. Check out the API reference (link below) to learn about the other useful properties it has.
|
||||||
|
|
||||||
### Reference
|
## Reference
|
||||||
API docs are generated automatically. View them here:
|
API docs are generated automatically. View them here:
|
||||||
|
|
||||||
<https://starbeamrainbowlabs.com/code/powahroot/docs/>
|
<https://starbeamrainbowlabs.com/code/powahroot/docs/>
|
||||||
|
|
Loading…
Reference in a new issue