简体   繁体   中英

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:

module.exports.routes = {
    '/foo': {response: 'notFound'}
};

This searches for the notFound.js file in the /response directory, which I've in there.

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:

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 call res.notFound() and you can override the default notFound():

res.notFound() (like other userland response methods) can be overridden or modified. It runs the response method defined in /responses/notFound.js, which is bundled automatically in newly generated Sails apps. If a notFound.js response method does not exist in your app, Sails will implicitly use the default behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM