gpt4 book ai didi

javascript - 如何在模型中编写多个远程方法?

转载 作者:行者123 更新时间:2023-12-03 06:24:22 25 4
gpt4 key购买 nike

可能有点棘手,或者我太笨了,无法弄清楚。每documentation示例说明了如何编写远程方法,但不是多个方法。就我而言,我已经编写了一个远程方法并且它工作得很好。

module.exports = function(customer) {
customer.signup = function(data, cb) {
customer.create(data, function(err, response){
cb(err, response);
});
};

customer.remoteMethod(
'signup',
{
accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
returns: {type: 'object', root: true}
}
);
};

当我尝试添加另一个远程方法时,它无法按要求工作,可能是由于某些语法错误。

module.exports = function(customer) {
customer.signup = function(data, cb) {
customer.create(data, function(err, response){
cb(err, response);
});
};

customer.remoteMethod(
'signup',
{
accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
returns: {type: 'object', root: true}
}
);

customer.resetPassword = function (data, cb) {
console.log(data);
cb(null, data);
};
customer.remoteMethod(
'resetPassword',
{
accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
returns: {type: 'object', root: true}
}
);
};

我什至尝试了一些变体,将remoteMethods声明合并到数组等中,但没有一个有效。哪里不对请指出。

最佳答案

您需要指定它们的路径。

customer.signup = function(data, cb) {
customer.create(data, function(err, response){
cb(err, response);
});
};

customer.remoteMethod(
'signup',
{
accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
returns: {type: 'object', root: true},
http: {
path: "/signup",
verb: 'post',
status: 201
}
}
);

customer.resetPassword = function (data, cb) {
console.log(data);
cb(null, data);
};
customer.remoteMethod(
'resetPassword',
{
accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
returns: {type: 'object', root: true},
http: {
path: "/reset-password",
verb: 'post',
status: 201
}
}
);

关于javascript - 如何在模型中编写多个远程方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38718139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com