Closed jaumard closed 8 years ago
I'm seeing policies working in my trailpack-hapi work with footprints. (we define also a FootprintPolicy
which guards the FootprintController
with various validation).
Can you post the Policy you wrote?
In fact my test was really simple. I just put this in my policy :
module.exports = {
test: function (req, reply) {
console.log('test');
}
}
With a breakpoint on console
and another on my controller method and only the breakpoint in the controller stop. So policy is not called at all.
@jaumard I think this is resolved, yes? Can you check
Hum now I have :
Trace: [Error: Invalid methodObject options {
"name": "DefaultPolicy.test",
"method" [1]: -- missing --
}
[1] "method" is required]
at TrailsApp.stop (/Users/jaumard/Downloads/testTrails/node_modules/trails/index.js:70:15)
at /Users/jaumard/Downloads/testTrails/node_modules/trails/lib/trailpack.js:45:27
at process._tickDomainCallback (node.js:400:9)
at Function.Module.runMain (module.js:477:11)
at startup (node.js:118:18)
at node.js:952:3
error:
Error: Invalid methodObject options {
"name": "DefaultPolicy.test",
"method" [1]: -- missing --
}
[1] "method" is required
at Object.exports.contain.exports.reachTemplate.exports.assert.condition [as assert] (/Users/jaumard/Downloads/testTrails/node_modules/hapi/node_modules/hoek/lib/index.js:732:11)
at Object.exports.apply (/Users/jaumard/Downloads/testTrails/node_modules/hapi/lib/schema.js:17:10)
at internals.Methods.add (/Users/jaumard/Downloads/testTrails/node_modules/hapi/lib/methods.js:33:29)
at module.exports.internals.Plugin.internals.Plugin.register.internals.Plugin.method (/Users/jaumard/Downloads/testTrails/node_modules/hapi/lib/plugin.js:527:31)
at Object.registerMethods (/Users/jaumard/Downloads/testTrails/node_modules/trailpack-hapi/lib/server.js:59:12)
at /Users/jaumard/Downloads/testTrails/node_modules/trailpack-hapi/index.js:44:20
at process._tickDomainCallback (node.js:400:9)
at Function.Module.runMain (module.js:477:11)
at startup (node.js:118:18)
at node.js:952:3
With policy :
'use strict'
const Policy = require('trails-policy')
/**
* @module DefaultPolicy
* @description TODO document Policy
*/
module.exports = class DefaultPolicy extends Policy {
test(request, reply) {
console.log('test');
reply()
}
}
And it's added under policies/index.js
. Maybe an example on trails-example-app
would be nice ^^
I try to set a policy to the
DefaultController
but it doesn't seems to be called, only controller method is called. An example will be good under https://github.com/trailsjs/trails-example-app