Render 404 pages for unmatched routes
This commit is contained in:
+18
@@ -225,6 +225,24 @@ async function start() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
const pathName = String(req.originalUrl || '');
|
||||||
|
const wantsHtml = !pathName.startsWith('/api/') && (!req.accepts || req.accepts('html'));
|
||||||
|
|
||||||
|
if (!wantsHtml) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(404).send(pages.renderErrorPage({
|
||||||
|
statusCode: 404,
|
||||||
|
title: 'Not found',
|
||||||
|
errorTitle: 'Oops! Page not found.',
|
||||||
|
message: 'We could not find the page you were looking for.',
|
||||||
|
backUrl: req.currentUser ? '/admin' : '/login',
|
||||||
|
backLabel: req.currentUser ? 'Back to dashboard' : 'Sign in'
|
||||||
|
}, req.currentUser));
|
||||||
|
});
|
||||||
|
|
||||||
app.use(function (error, req, res, _next) {
|
app.use(function (error, req, res, _next) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const statusCode = Number(error && (error.statusCode || error.status)) || 500;
|
const statusCode = Number(error && (error.statusCode || error.status)) || 500;
|
||||||
|
|||||||
Reference in New Issue
Block a user