2017-07-28 41 views
0

是否有可能为loopback中的所有api调用编写一个通用的beforeRemote钩子。目前,我能写beforeRemote挂钩所有API在通过该模型特定的模型对象,如:Beforeremote所有的api调用loopback

modelObj.beforeRemote('*', function (ctx, req, next) { 
    //code 
    next() 
}); 

同样是有可能写一个远程前对所有API调用。任何帮助,将不胜感激!谢谢!

回答

1

我得到了答案,我在这里发布它,以便有人可以在相同的情况下使用它。 在引导脚本文件,使用下面的代码:

module.exports = function(app) { 
    var remotes = app.remotes(); 
    remotes.before('**', function (ctx, next) { 
    //Code to execute before all api calls goes here 
    next(); 
    }); 
}; 

完蛋了!!!!