Esiste un modo per eseguire un'azione/una funzione prima di tutte e tutte le azioni definite in un controller Sails? Simile ai ganci beforeCreate
nei modelli.Prima delle azioni nel controller Sails
Per esempio nel mio DataController, ho le seguenti azioni:
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...
}
};
Posso fare qualcosa di simile a quanto segue:
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...
}
};
Dove qualsiasi chiamata a qualsiasi azione definita passerà attraverso la beforeAction primo?
utilizzare le politiche, invece, renderà il codice sia più chiare –