You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Load from your spool config. (This pack is included by default).
20
20
21
21
```js
22
-
// config/main.js
23
-
module.exports= {
22
+
// config/main.ts
23
+
import { RouterSpool } from'@fabrix/spool-router'
24
+
exportconstmain= {
24
25
// ...
25
26
spools: [
26
-
require('spool-router').Router
27
+
RouterSpool
27
28
]
28
29
}
29
30
```
@@ -43,7 +44,7 @@ export const router = {
43
44
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.
44
45
45
46
##### 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.
47
48
48
49
#### `config.routes`
49
50
The list of route objects to be compiled for use by the webserver.
@@ -128,7 +129,7 @@ Optionally:
128
129
// ...
129
130
}
130
131
```
131
-
The Configuration about, will ignore any prefix given to it.
132
+
The Configuration above, will ignore any prefix given to it.
132
133
133
134
Optionally:
134
135
@@ -146,6 +147,33 @@ Optionally:
146
147
```
147
148
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`
148
149
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
+
149
177
## Tapestries and Policies
150
178
151
179
Support for tapestries and Policies is provided by [spool-tapestries](https://github.com/fabrix-app/spool-tapestries).
0 commit comments