1
我有一個名爲「用戶」和動作控制器稱爲「註冊」,然後我也被稱爲政策「的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/
被訪問它將剝離斜線並重定向到:http://localhost:{{port}}/user/signup
這是完美的作品!
除此之外,每當我嘗試並參觀http://localhost:{{port}}/user/signup/////
例如它只是拋出一個404甚至不通過任何我在配置設置政策的運行/ 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'],
},
}
謝謝!通過你的答案,它完美的工作。 –