Trailpack Router. Aggregates all routes from config.routes and attaches
prerequisites (Policies) to form hapi.js route objects.
Load from your trailpack config. (This pack is included by default).
// config/main.js
module.exports = {
// ...
packs: [
require('trailpack-core'),
require('trailpack-router')
]
}The policies configuration maps controller handlers to a list of policies which must pass before the handler is invoked.
// config/policies.js
module.exports = {
'*': [ 'GlobalPolicy.test' ], // Apply GlobalPolicy.test to all handler except the ones below
ExampleController: {
test: [ 'ExamplePolicy.test' ]
},
Example2Controller: [ 'ExamplePolicy.test' ], // Apply ExamplePolicy.test to all handler
Example3Controller: {
'*': [ 'GlobalExample3Policy.test' ], // Apply GlobalExample3Policy.test to all handler except the ones below
test: [ 'OverridePolicy.test' ]
}
}The list of route objects to be compiled for use by the webserver.
// config/routes.js
module.exports = [
{
method: [ 'GET' ],
path: '/example/test',
handler: 'ExampleController.test'
}
]During initialization, for the above example, a route object will be compiled that takes the following form:
{
method: [ 'GET' ],
path: '/example/test',
handler: 'ExampleController.test',
config: {
pre: [ 'ExamplePolicy.test' ]
}
}- trailpack-hapi
- trailpack-express4 (In Progress)
- trailpack-koa (TODO)
We love contributions! Please see our Contribution Guide for more information.