我的脚本中有一部分需要使用一个函数,该函数将 req
和 res
数据作为其变量。
有什么方法可以填充它们而无需实际提交表单,例如
req.body.entry.body = 'this is a test post about things that are apples';
和
res.locals.user.uid = node.uid;
然后调用
entries.submit(req, res, next);
谢谢!
最佳答案
这取决于您调用 entries.submit
的函数所在的位置,并且可能有一种更清晰的方法来构造您所要求的内容。但你的粗略答案是
someOtherFunction = function(req, res, next) {
myReq = {
body: {
entry: {
body: "this is a test post about things that are apples"
}
}
};
myRes = {
locals: {
user: {
uid: node.uid
}
}
};
entries.submit(myReq, myRes, next);
}
关于javascript - 修改req.body和res。 Node.Js/Express 应用程序中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23871052/