如何在一个模型中编写多个远程方法?
How to write multiple remote methods in a model?
可能有点棘手,或者我太笨了。每个 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 声明合并到数组等中,但 none 会起作用。请指出我哪里不对。
您需要为它们指定路径。
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
}
}
);
可能有点棘手,或者我太笨了。每个 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 声明合并到数组等中,但 none 会起作用。请指出我哪里不对。
您需要为它们指定路径。
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
}
}
);