user3046205
user3046205

Reputation: 131

sails.js preload action in controller

I need a help in sails.js framework.i am developing the website in nodejs and sails.js framework. is there any way to call preload action in each controller.(for ex: the controller calling time load this action).each controller having different pre load action.

Please any one suggest to me.how can i create this way or any other way.

Thanks to all.

Upvotes: 0

Views: 187

Answers (1)

mdunisch
mdunisch

Reputation: 3697

use a service:

/service/mypre.js:

exports.first = function(req,res,cb) {
     // here add you code

     cb();
}   

in Controller:

module.exports = {
    index: function(req,res) {
       sails.mypre.first(req,res, function(){

          // Do other things...
       });

    }
}

And you may add a callback to make sure, your mypre() is done completely.

Upvotes: 1

Related Questions