Node.js Node Express返回404自定义消息
我将NodeJS与Express一起使用,当找不到端点时,Express返回 每当未键入端点时,我希望返回一条自定义404消息,而不是上面的图像 我已尝试将以下内容添加到Node.js Node Express返回404自定义消息,node.js,express,Node.js,Express,我将NodeJS与Express一起使用,当找不到端点时,Express返回 每当未键入端点时,我希望返回一条自定义404消息,而不是上面的图像 我已尝试将以下内容添加到app.js app.use(function (req, res, next) { res.status(404).send("Sorry can't find that!") }) 但这只返回所有带有 对不起,我找不到 您需要将此设置为app.js中的最后一个“路由” app.use(function (req, re
app.js
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
但这只返回所有带有
对不起,我找不到
您需要将此设置为app.js中的最后一个“路由”
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
指定路线的顺序很重要