Gibt es eine Möglichkeit, eine Aktion/Funktion vor allen Aktionen auszuführen, die in einem Sails-Controller definiert sind? Ähnlich wie die beforeCreate
Haken in den Modellen.Vor Aktionen in Sails-Controller
Zum Beispiel in meinem Datacontroller, habe ich die folgenden Aktionen:
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...
}
};
Kann ich so etwas wie die folgenden Möglichkeiten:
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...
}
};
Wo jeder Anruf auf eine beliebige definierte Aktion wird die beforeAction passieren zuerst?
Nutzungsrichtlinien statt, es wird Ihr Code sieht klarer –