diff --git a/src/web.js b/src/web.js index 6a383df..b1cecd5 100644 --- a/src/web.js +++ b/src/web.js @@ -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) { console.error(error); const statusCode = Number(error && (error.statusCode || error.status)) || 500;