Joss
Joss

Reputation: 555

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!

Upvotes: 1

Views: 1587

Answers (1)

M-A. Fernandes
M-A. Fernandes

Reputation: 550

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.

Upvotes: 1

Related Questions