如何将策略应用于错误?

我有一个名为“用户”的控制器和一个名为“注册”的行动,然后我有一个叫“stripSlashes”与下面的代码的政策:

module.exports = function(req, res, next) { if(req.url.substr(-1) === '/' && req.url.length > 1){ res.redirect(req.url.slice(0, -1), 301); } else { next(); } }; 

我试图做的是无论何时访问http://localhost:{{port}}/user/signup/ ,它都会去掉斜线并redirect到: http://localhost:{{port}}/user/signup这完美的作品!

除此之外,每当我尝试访问http://localhost:{{port}}/user/signup///// ,它只会抛出一个404,甚至不会运行我在configuration中设置的任何策略/policies.js

所以,我的问题是如何将我的自定义策略应用到所有事情,包括错误页面(即404s)

先谢谢了!


Policies.js供参考:

 module.exports.policies = { '*': ['flash', 'stripSlashes', 'wwwRedirect'], user: { edit: ['flash', 'isAuthenticated', 'stripSlashes', 'wwwRedirect'], update: ['flash', 'isAuthenticated', 'stripSlashes', 'wwwRedirect'], show: ['flash', 'isAuthenticated', 'stripSlashes', 'wwwRedirect'], index: ['flash', 'isAuthenticated', 'stripSlashes', 'wwwRedirect'], destroy: ['flash', 'isAuthenticated', 'stripSlashes', 'wwwRedirect'], }, } 

政策必须匹配要应用的政策路线。 如果您想将此规则应用于所有api端点,则可以使用快速定制中间件。 请参阅此处的堆栈溢出答案: 使用sails.js修改响应头以实现HSTS