-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
44 lines (39 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const Trailpack = require('trailpack')
const lib = require('./lib')
/**
* trailpack-router
*
* Unify all route handlers into a single, standard route object format. Route
* objects are structured as Hapi.js routes.
*
* @see http://hapijs.com/api#route-configuration
* @see https://github.com/trailsjs/trailpack-hapi
* @see https://github.com/trailsjs/trailpack-koa
* @see https://github.com/trailsjs/trailpack-express4
*/
module.exports = class Router extends Trailpack {
validate () {
return Promise.all([
Promise.all(this.app.config.get('routes').map(lib.Validator.validateRoute)),
lib.Validator.validateRouteList(this.app.config.get('routes'))
])
}
/**
* Compile route configuration and store in app.routes. Trailpacks that wish
* to extend/add new routes should do so either in their configure() lifecycle
* method, or by creating a config.routes list -- this list will be
* automatically merged into the application's config.routes list.
*/
initialize () {
this.app.routes = this.app.config.get('routes')
.map(route => lib.Util.buildRoute(this.app, route))
.filter(route => !!route)
}
constructor (app) {
super(app, {
config: { },
api: { },
pkg: require('./package')
})
}
}