node.js - Sails Hook route forbidden -
i try make installable hook make security verifications under hook.js set :
routes : { before : { "/" : function (req, res, view) { ..... res.forbidden(); } } },
and have error if try send forbidden page user :
error: sending 500 ("server error") response: typeerror: object #<serverresponse> has no method 'view' @ object.forbidden (/users/jaumard/documents/workspaceide/kikilib/api/responses/forbidden.js:56:19) @ serverresponse.bound [as forbidden] (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21) @ isrouteallowed (/users/jaumard/documents/workspaceide/kikilib/api/hooks/acl.js:66:18) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) @ pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) @ nextroute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11) @ /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7 @ /usr/local/lib/node_modules/sails/lib/hooks/i18n/index.js:35:7 @ object.i18ninit [as init] (/usr/local/lib/node_modules/sails/node_modules/i18n/i18n.js:89:5) @ addlocalizationmethod (/usr/local/lib/node_modules/sails/lib/hooks/i18n/index.js:33:11) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) [typeerror: object #<serverresponse> has no method 'view'] error: server error: error: typeerror: object #<serverresponse> has no method 'view' @ object.forbidden (/users/jaumard/documents/workspaceide/kikilib/api/responses/forbidden.js:56:19) @ serverresponse.bound [as forbidden] (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21) @ isrouteallowed (/users/jaumard/documents/workspaceide/kikilib/api/hooks/acl.js:66:18) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) @ pass (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) @ nextroute (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11) @ /usr/local/lib/node_modules/sails/lib/router/bind.js:187:7 @ /usr/local/lib/node_modules/sails/lib/hooks/i18n/index.js:35:7 @ object.i18ninit [as init] (/usr/local/lib/node_modules/sails/node_modules/i18n/i18n.js:89:5) @ addlocalizationmethod (/usr/local/lib/node_modules/sails/lib/hooks/i18n/index.js:33:11) @ routetargetfnwrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:179:5) @ callbacks (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) @ param (/usr/local/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) [typeerror: object #<serverresponse> has no method 'view']
i'm under sails 0.11.0. don't use policies cause policies apply controller action , want make acl view, controller , more...
all source code available here : https://github.com/jaumard/sails-hook-user-acl
for use : res.status(403).send("<h1>" + req.__("forbidden") + "</h1>");
instead of res.forbidden();
nice send view
just found workaround :
var _addresviewmethod = require("../sails/lib/hooks/views/res.view.js"); routes : { before : { "/office" : function (req, res, view) { ..... _addresviewmethod(req, res, function(){ res.forbidden(); }); } } },
edit : better way given sails team here https://github.com/balderdashy/sails/issues/2799#issuecomment-115333582
// wait router initialized sails.on('router:before', function () { // wait views hook load, routes bound first // (including 1 mixes in res.view) sails.after('hook:views:loaded', function () { // bind routes here sails.router.bind('/office', officehandler, 'get', {}); }); function officehandler(req, res) {...res.forbidden()...} return cb(); });
Comments
Post a Comment