如何将 express.js 请求直接重定向到 404
how to redirect express.js request directly to 404
如果用户未通过身份验证,我想将请求发送到 express.js 内的某个路由,直接发送到 404。
在我的中间件中,我有以下代码:
exports.isAuthenticated = function (req, res, next) {
if (req.isAuthenticated()) {
next();
} else {
res.redirect("/login");
}
};
我想做的是改为向用户显示 404 页面。我已经全局配置了一个,但我不知道我应该如何跳过请求的每个链接中间件并将用户直接发送到 404。
感谢您的回答:)
好的,我得到了答案。我必须使用
If you need to skip the rest of the middleware from a router
middleware stack, call next('route') to pass on the control to the
next route. Note: next('route') will work only in middleware loaded
using app.VERB() or router.VERB().
如果用户未通过身份验证,我想将请求发送到 express.js 内的某个路由,直接发送到 404。
在我的中间件中,我有以下代码:
exports.isAuthenticated = function (req, res, next) {
if (req.isAuthenticated()) {
next();
} else {
res.redirect("/login");
}
};
我想做的是改为向用户显示 404 页面。我已经全局配置了一个,但我不知道我应该如何跳过请求的每个链接中间件并将用户直接发送到 404。
感谢您的回答:)
好的,我得到了答案。我必须使用
If you need to skip the rest of the middleware from a router middleware stack, call next('route') to pass on the control to the next route. Note: next('route') will work only in middleware loaded using app.VERB() or router.VERB().