当我转到指定的路由时,我有一个路由处理程序,它在身份验证控制器中调用一个注册函数:
module.exports = app => {
app.post("/signup", authentication.signup());
};我的管理员:
exports.signup = function(req, res, next) {
res.send({ success: true });
};但是当我启动服务器时,我说它不能读取未定义的属性“发送”。由于无法运行我的服务器,我不能使用postman来测试我的API路由。
为什么它要打电话发送,甚至在我访问过这条路线之前?我正在使用我的快递应用程序的节点http库运行我的服务器。
发布于 2017-10-24 11:01:26
app.post("/signup", authentication.signup()); 调用 authentication.signup并将其返回值传递给app.post,就像foo(bar()) 调用 bar并将其返回值传递给foo一样。
相反,只需将函数本身传递到app.post;Express稍后将调用它,以响应该路由上的帖子:
module.exports = app => {
app.post("/signup", authentication.signup);
// No () here ---------------------------^
};https://stackoverflow.com/questions/46908694
复制相似问题