Add express middleware for param validations
node.js, sails.js
Solution
Adding express-middleware in a sails application is simple.
create a new policy.
policies
|_
middleware.js / .coffee
Add Express Middleware`YOUR_MIDDLE_WARE_FILE_NAME.js`
Inside your middleware file we create the standard export for node.js
module.exports = require('middle-ware')(OPTIONS_GO_HERE) // See middleware docs for configuration settings.
Then once you have created the middleware you can apply it to all requests or a single controller by following the Sails.js convension.
Entire Application`policies.js`
module.exports.policies = {
'*':['middleware'] // node same name as file without extention
}
Single Controller Action `policies.js`
module.exports.policies = {
RabbitController:{
feed:['middleware']
}
}
Problem
In a sails.js application is there a simple way of including `express-middleware`? For instance extending the request object with `express-validator`.