【发布时间】:2018-04-04 03:46:33
【问题描述】:
我很难找到有关重定向到模型函数内的 URL 或 remoteMethod 的任何文档。这里有人已经这样做了吗?请在下面找到我的代码。
模型内部的函数(暴露 /catch 端点)
Form.catch = function (id, data, cb) {
Form.findById(id, function (err, form) {
if (form) {
form.formentries.create({"input": data},
function(err, result) {
/*
Below i want the callback to redirect to a url
*/
cb(null, "http://google.be");
});
} else {
/*
console.log(err);
*/
let error = new Error();
error.message = 'Form not found';
error.statusCode = 404;
cb(error);
}
});
};
Form.remoteMethod('catch', {
http: {path: '/catch/:id', verb: 'post'},
description: "Public endpoint to create form entries",
accepts: [
{arg: 'id', type: 'string', http: {source: 'path'}},
{arg: 'formData', type: 'object', http: {source: 'body'}},
],
returns: {arg: 'Result', type: 'object'}
});
【问题讨论】:
标签: javascript express loopbackjs loopback