From 072ad9785bf6bd0ec024e0ce41e9f74a425c0d69 Mon Sep 17 00:00:00 2001 From: Weyland Joyner Date: Mon, 21 Dec 2015 16:07:44 -0500 Subject: [PATCH 1/4] changed route handling to deal with objects --- lib/xfmr.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/xfmr.js b/lib/xfmr.js index f97ef72..315574e 100644 --- a/lib/xfmr.js +++ b/lib/xfmr.js @@ -59,11 +59,14 @@ 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)) { + policies = policiesConfig.directories[route.handler.directory.path] + } return { config: { From f1173f4fcb752ec3c845076b3c6d6a18dc78594a Mon Sep 17 00:00:00 2001 From: Weyland Joyner Date: Wed, 30 Dec 2015 11:19:08 -0800 Subject: [PATCH 2/4] added policiesConfig for serving file --- lib/xfmr.js | 9 ++++++++- package.json | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/xfmr.js b/lib/xfmr.js index 315574e..a56db34 100644 --- a/lib/xfmr.js +++ b/lib/xfmr.js @@ -2,6 +2,7 @@ const _ = require('lodash') const Footprints = require('./footprints') +const Hoek = require('Hoek') const lib = require('./') module.exports = { @@ -65,7 +66,13 @@ module.exports = { policies = _.get(policiesConfig, route.handler) } else if (_.isPlainObject(route.handler)) { - policies = policiesConfig.directories[route.handler.directory.path] + 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 { diff --git a/package.json b/package.json index f2c2796..8ebfe69 100644 --- a/package.json +++ b/package.json @@ -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" From 5c514410a27c6d54446d23e207a0e796b0b3a359 Mon Sep 17 00:00:00 2001 From: Weyland Joyner Date: Wed, 30 Dec 2015 11:24:22 -0800 Subject: [PATCH 3/4] linted curly braces --- lib/xfmr.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/xfmr.js b/lib/xfmr.js index a56db34..9b64d70 100644 --- a/lib/xfmr.js +++ b/lib/xfmr.js @@ -68,9 +68,11 @@ module.exports = { else if (_.isPlainObject(route.handler)) { if (route.handler.directory) { policies = policiesConfig.directories[route.handler.directory.path] - } else if (route.handler.file) { + } + else if (route.handler.file) { policies = policiesConfig.files[route.handler.file] - } else { + } + else { Hoek.assert(!route.handler.directory && !route.handler.file, 'policy not recognized') } } From 90dbd823465ff57591a94d80327844d0c8621284 Mon Sep 17 00:00:00 2001 From: Weyland Joyner Date: Wed, 30 Dec 2015 11:26:15 -0800 Subject: [PATCH 4/4] and trailing spaces --- lib/xfmr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xfmr.js b/lib/xfmr.js index 9b64d70..47afdc0 100644 --- a/lib/xfmr.js +++ b/lib/xfmr.js @@ -68,10 +68,10 @@ module.exports = { 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') }