From bade2f9b862fde4080f7fa8c9db67b5c18fc3293 Mon Sep 17 00:00:00 2001 From: sherl Date: Tue, 9 Dec 2025 12:49:55 +0100 Subject: [PATCH] feat: add 404 handling --- src/app.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app.ts b/src/app.ts index d312632..2e9b931 100644 --- a/src/app.ts +++ b/src/app.ts @@ -25,5 +25,18 @@ app.use(router); if (process.env.DEBUG === "true") { app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); } + +// Handle 404s +// https://stackoverflow.com/a/9802006 +app.use(function(req, res) { + res.status(404); + + if (req.accepts('json')) { + res.json({ status: 'error', error: 'Not found' }); + return; + } + + res.type('txt').send('Not found'); +}); app.listen(6567, () => console.log('(HTTP Server) Listening on port 6567.'));