Routes are rules that tell Sails what to do when faced with an incoming request.
Routes are defined in config/routes.js
. The order of the routes is significant, as routes are matched top down. This means if you have a specific route that also could be matched by a wildcard route, the specific route should be defined above the wildcard route.
When a request enters your application sails.js grabs all the parameters that came with it and makes them available for you as params
on the request object.
Properties in the route target object will be passed through to the route handler in the req.options object. The following are reserved properties that can affect the behavior of the route handler:
Property | Applicable Target Types | Data Type | Details |
---|---|---|---|
skipAssets | all | Boolean | Set to true if you don't want the route to match URLs with dots in them (e.g. myImage.jpg). This will keep your routes with wildcard notation from matching URLs of static assets. Useful when creating URL slugs. |
skipRegex | all | Regexp | If skipping every URL containing a dot is too permissive, or you need a route's handler to be skipped based on different criteria entirely, you can use skipRegex . This option allows you to specify a regular expression or array of regular expressions to match the request URL against; if any of the matches are successful, the handler is skipped. Note that unlike the syntax for binding a handler with a regular expression, skipRegex expects _actual RegExp objects, not strings. |
locals | controller, view, blueprint, response | Dictionary | Sets default local variables to pass to any view that is rendered while handling the request. |
cors | all | Dictionary or Boolean or String | Specifies how to handle requests for this route from a different origin. |
populate | blueprint | Boolean | Indicates whether the results in a "find" or "findOne" blueprint action should have associated model fields populated. Defaults to the value set in config/blueprints.js . |
skip, limit, sort, where | blueprint | Dictionary | Set criteria for "find" blueprint. |