Skip to content

Commit 05d8fc6

Browse files
authored
Merge pull request #10 from fabrix-app/v1.1
V1.1
2 parents 05d939a + 6e59980 commit 05d8fc6

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

README.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ $ npm install @fabrix/spool-router --save
1919
Load from your spool config. (This pack is included by default).
2020

2121
```js
22-
// config/main.js
23-
module.exports = {
22+
// config/main.ts
23+
import { RouterSpool } from '@fabrix/spool-router'
24+
export const main = {
2425
// ...
2526
spools: [
26-
require('spool-router').Router
27+
RouterSpool
2728
]
2829
}
2930
```
@@ -43,7 +44,7 @@ export const router = {
4344
This will sort the routes based on the key (path) either ascending or descending. This is used in spools like Express where the order of routes matters.
4445

4546
##### router.prefix
46-
This config is optional and can be left as `''`. This will prefix each route with the specified prefix.
47+
This config is optional and can be left as `''` or `null`. This will prefix each route with the specified prefix.
4748

4849
#### `config.routes`
4950
The list of route objects to be compiled for use by the webserver.
@@ -128,7 +129,7 @@ Optionally:
128129
// ...
129130
}
130131
```
131-
The Configuration about, will ignore any prefix given to it.
132+
The Configuration above, will ignore any prefix given to it.
132133

133134
Optionally:
134135

@@ -146,6 +147,33 @@ Optionally:
146147
```
147148
The configuration above will take the configuration of another config attribute, in this case: `app.config.customPrefixer.prefix` is set to `/custom/endpoint` so the resulting route prefix will be `/custom/endpoint/example/test`
148149

150+
Finally, you can also provide 2 different prefixes for the same route with different methods.
151+
152+
```js
153+
{
154+
// ...
155+
'/example/test': {
156+
'GET': {
157+
handler: 'ExampleController.get',
158+
config: {
159+
prefix: '/api/v1'
160+
pre: [ 'ExamplePolicy.get' ]
161+
}
162+
},
163+
'POST': {
164+
handler: 'ExampleController.post',
165+
config: {
166+
prefix: '/api/v2'
167+
pre: [ 'ExamplePolicy.post' ]
168+
}
169+
}
170+
}
171+
// ...
172+
}
173+
```
174+
175+
The configuration above will produce 2 routes, one for `GET /api/v1/example/test` and one for `POST /api/v2/example/test` respecting their prefixes. This is useful for when one method may still be on an older API than the other or they need to be handled differently.
176+
149177
## Tapestries and Policies
150178

151179
Support for tapestries and Policies is provided by [spool-tapestries](https://github.com/fabrix-app/spool-tapestries).
@@ -162,8 +190,8 @@ for more information.
162190
## License
163191
[MIT](https://github.com/fabrix-app/spool-router/blob/master/LICENSE)
164192

165-
[npm-image]: https://img.shields.io/npm/v/spool-router.svg?style=flat-square
166-
[npm-url]: https://npmjs.org/package/spool-router
193+
[npm-image]: https://img.shields.io/npm/v/@fabrix/spool-router.svg?style=flat-square
194+
[npm-url]: https://npmjs.org/package/@fabrix/spool-router
167195
[ci-image]: https://img.shields.io/circleci/project/github/fabrix-app/spool-router/master.svg
168196
[ci-url]: https://circleci.com/gh/fabrix-app/spool-router/tree/master
169197
[daviddm-image]: http://img.shields.io/david/fabrix-app/spool-router.svg?style=flat-square

0 commit comments

Comments
 (0)