Spool Router. Aggregates all routes from config.routes
to create hapi.js route objects.
$ npm install @fabrix/spool-router --save
Load from your spool config. (This pack is included by default).
// config/main.js
module.exports = {
// ...
spools: [
require('spool-router').Router
]
}
The Router takes a few Configuration values
// config/router.ts
export const router = {
sortOrder: 'asc', // (asc | desc)
prefix: '/api/v1'
}
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.
This config is optional and can be left as ''
. This will prefix each route with the specified prefix.
The list of route objects to be compiled for use by the webserver.
// config/routes.ts
const routes = {
'/example/test': {
'GET': 'ExampleController.test'
}
}
During initialization, for the above example, a route object will be compiled that takes the following form:
{
// ...
'/example/test': {
'GET': 'ExampleController.test',
config: {
pre: [ 'ExamplePolicy.test' ]
}
}
// ...
}
{
// ...
'/example/test': {
'GET': 'ExampleController.test',
config: {
prefix: '/api/v2'
}
}
// ...
}
The Configuration above, will give this route a prefix of /api/v2
instead of using the config.prefix
that was specified
Optionally:
{
// ...
'/example/test': {
'GET': 'ExampleController.test',
config: {
prefix: false
}
}
// ...
}
The Configuration about, will ignore any prefix given to it.
Optionally:
{
// ...
'/example/test': {
'GET': 'ExampleController.test',
config: {
prefix: 'customPrefixer.prefix'
}
}
// ...
}
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
Support for tapestries and Policies is provided by spool-tapestries.
- spool-express
- spool-hapi (TODO)
- spool-koa (TODO)
We love contributions! Please see our Contribution Guide for more information.