You can do this via a Sails policy by setting some properties on req.options
. If you have a User
model and are using the blueprint create
route, then in your config/policies you'd have:
UserController: {
create: 'setValues'
}
and in api/policies/setValues.js:
module.exports = function(req, res, next) {
req.options.values = req.options.values || {};
req.options.values.ip = <SET IP>;
req.options.values.agent = <SET USER AGENT>;
return next();
};
I don't remember the preferred way to get user IP, but this question looks promising. For user agent you can try req.headers['user-agent']
.
If you're using a custom controller action rather than the blueprints, this will still work fine, you'll just need to merge the values passed with the request with req.options.values
.