req.options
req.options allows altering of (or providing defaults for) request parameters without modifying the original object.
Any properties provided in a custom route configuration are made available in the req.options object. For example, given the following in config/routes.js:
"GET /foo": {controller: 'user', action: 'myAction', owl: 'hoot'}
req.options.controller, req.options.action and req.options.owl will all be available.
Additionally, several special req.options objects are available for use with blueprints, specifically to programatically change the criteria and/or values that a blueprint action uses when accessing a data store. These are best used in policies to, for example, filter requested records based on the logged-in user.
Example
In a config/policies/filterByUser.js policy:
module.exports = function filterByUser (req, res, next) {
if (req.session.user) {
req.options.where = req.options.where || {};
req.options.where.userId = req.session.user.id;
}
return next();
}