所有 api 调用环回之前的远程
Beforeremote for all api calls loopback
是否可以为环回中的所有 api 调用编写一个通用的 beforeRemote 挂钩。目前,我可以通过该模型对象为特定模型中的所有 api 编写 beforeRemote 挂钩,例如:
modelObj.beforeRemote('*', function (ctx, req, next) {
//code
next()
});
同样可以在远程之前为所有 api 调用编写一个。任何帮助,将不胜感激!谢谢!
我得到了答案并将其张贴在这里,以便有人可以在相同情况下使用它。
在引导脚本文件中,使用以下代码:
module.exports = function(app) {
var remotes = app.remotes();
remotes.before('**', function (ctx, next) {
//Code to execute before all api calls goes here
next();
});
};
就是这样!!!!
是否可以为环回中的所有 api 调用编写一个通用的 beforeRemote 挂钩。目前,我可以通过该模型对象为特定模型中的所有 api 编写 beforeRemote 挂钩,例如:
modelObj.beforeRemote('*', function (ctx, req, next) {
//code
next()
});
同样可以在远程之前为所有 api 调用编写一个。任何帮助,将不胜感激!谢谢!
我得到了答案并将其张贴在这里,以便有人可以在相同情况下使用它。 在引导脚本文件中,使用以下代码:
module.exports = function(app) {
var remotes = app.remotes();
remotes.before('**', function (ctx, next) {
//Code to execute before all api calls goes here
next();
});
};
就是这样!!!!