我想在回环中扩展用户登录POST方法。
到目前为止,我已经扩展了基本用户类以推出自己的类,但是如何向特定端点添加功能呢?
发布于 2016-03-14 18:14:10
在本例中,我创建了一个名为"UserAuth2“的新模型,它扩展了LoopbackJS提供的现有用户模型。我使用slc loopback:model工具创建了模型。
为了在回收站中扩展函数,请在模型的JS文件中使用以下代码:
module.exports = function(UserAuth2) {
// Get reference to endpoint
var previousImplementation = UserAuth2.login;
// Create new implementation of endpoint
UserAuth2.login = function(){
//Get existing implementation
/*** arguments is an array of existing arguments that the login
function takes***/
previousImplementation.apply(this, arguments);
//Extend the method and do something else here
console.log("New functionality");
}
}https://stackoverflow.com/questions/35993816
复制相似问题