[英]Not found route not found in Sailsjs
Based on Sailsjs documentation , it is possible to add on the routes file a response with a syntax like this:根据Sailsjs 文档,可以在路由文件中添加一个使用如下语法的响应:
module.exports.routes = {
'/foo': {response: 'notFound'}
};
This searches for the notFound.js
file in the /response
directory, which I've in there.这将在
/response
目录中搜索notFound.js
文件,我在那里。
So in my routes.js
file I've added this as the end of the other routes in order to catch the not found routes, it is something like this:因此,在我的
routes.js
文件中,我将其添加为其他路由的末尾以捕获未找到的路由,它是这样的:
module.exports.routes = {
'get /myroute/:myPara/': 'MyController.getAll',
'get /myroute/:myPara/': 'MyController.getOne',
'post /myroute/:myPara/': 'MyController.create',
'/*' : {response: 'notFound'}
};
I've realized that never finds the last route, I've also tried removing the slash ( doing '*'
), but nothing works.我意识到永远找不到最后一条路线,我也尝试删除斜线(执行
'*'
),但没有任何效果。
Am I missing something?我错过了什么吗? Thanks!
谢谢!
Sails already take care of the 404 notFound : here Sails 已经处理了 404 notFound : 这里
Sails call res.notFound() and you can override the default notFound(): Sails 调用 res.notFound() 并且您可以覆盖默认的 notFound():
res.notFound()
(like other userland response methods) can be overridden or modified.res.notFound()
(与其他用户空间响应方法一样)可以被覆盖或修改。 It runs the response method defined in /responses/notFound.js, which is bundled automatically in newly generated Sails apps.它运行 /responses/notFound.js 中定义的响应方法,该方法自动捆绑在新生成的 Sails 应用程序中。 If a notFound.js response method does not exist in your app, Sails will implicitly use the default behavior.
如果您的应用程序中不存在 notFound.js 响应方法,Sails 将隐式使用默认行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.