Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/xfmr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const _ = require('lodash')
const Footprints = require('./footprints')
const Hoek = require('Hoek')
const lib = require('./')

module.exports = {
Expand Down Expand Up @@ -59,11 +60,22 @@ module.exports = {
* the form "Controller.handler"
*/
getRoutePrerequisites (policiesConfig, route) {
const handlerTokens = route.handler.split('.')
const controller = handlerTokens[0]
const handler = handlerTokens[1]
let policies

const policies = _.get(policiesConfig, [ controller, handler ]) || [ ]
if (_.isString(route.handler)) {
policies = _.get(policiesConfig, route.handler)
}
else if (_.isPlainObject(route.handler)) {
if (route.handler.directory) {
policies = policiesConfig.directories[route.handler.directory.path]
}
else if (route.handler.file) {
policies = policiesConfig.files[route.handler.file]
}
else {
Hoek.assert(!route.handler.directory && !route.handler.file, 'policy not recognized')
}
}

return {
config: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Trailpack Router",
"main": "index.js",
"dependencies": {
"hoek": "^3.0.4",
"joi": "^7.0.0",
"lodash": "^3.10.1",
"trailpack": "latest"
Expand Down