【发布时间】:2022-01-19 11:47:10
【问题描述】:
我有一个 NodeJS 服务器,但我忘记在页面上添加 POST 路由。
我有一个 GET 路由,在 routes/public.js:
/**
* GET /festas
*
*
*/
router.get("/festas", async (req, res) => {
return res.render('festas', {
user: req.user,
text: TEXT, // equivalent of a global variable
});
});
router.get("/:token", async (req, res) => {
// Verifications, such as typos on the requested route,
// not shown here.
return res.redirect(301, "/404");
}
module.exports = router;
这个模块被app.js调用:
app.use('/', require('./routes/public'));
还有一个 PUG 模板:
.feedback
h2 #{text.feedback.title}
p #{text.feedback.body}
.container
form#commentForm(method="POST")
.comment
p #{text.feedback.comments}
input(type="text", name="commentString")
input.primary(type="submit", value="Submit")
当我点击页面上的提交按钮时,我看到:
Cannot POST /festas
但是我在错误日志中找不到这个错误。我想将此错误包含在错误日志中,以便将来快速发现此错误。
如何将缺失的 POST 路由添加到错误日志中?
【问题讨论】:
-
您能否添加更多细节和代码 sn-ps 有助于理解?
-
我添加了它们。谢谢!
标签: node.js logging error-handling