Is there a way to have an action/function executed before each and all actions defined in a Sails controller? Similar to the beforeCreate
hooks in the models.
For example in my DataController, I have the following actions:
module.exports = {
mockdata: function(req, res) {
var criteria = {};
// collect all params
criteria = _.merge({}, req.params.all(), req.body);
//...some more login with the criteria...
},
getDataForHost: function(req, res) {
var criteria = {};
// collect all params
criteria = _.merge({}, req.params.all(), req.body);
//...some more login with the criteria...
}
};
Can I do something like the following:
module.exports = {
beforeAction: function(req, res, next) {
var criteria = {};
// collect all params
criteria = _.merge({}, req.params.all(), req.body);
// store the criteria somewhere for later use
// or perhaps pass them on to the next call
next();
},
mockdata: function(req, res) {
//...some more login with the criteria...
},
getDataForHost: function(req, res) {
//...some more login with the criteria...
}
};
Where any call to any action defined will pass through the beforeAction first?