From a5dc505e613615a905f7f39e921f9d274b87fb36 Mon Sep 17 00:00:00 2001 From: Spappz <34202141+Spappz@users.noreply.github.com> Date: Sat, 25 Jan 2025 03:42:04 +0000 Subject: [PATCH] add 404 error-handling to server This is all that seems necessary according to Express? Admittedly my first time using it. https://expressjs.com/en/starter/faq.html#how-do-i-handle-404-responses --- default/public/error/url-not-found.html | 15 +++++++++++++++ server.js | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 default/public/error/url-not-found.html diff --git a/default/public/error/url-not-found.html b/default/public/error/url-not-found.html new file mode 100644 index 000000000..87974145f --- /dev/null +++ b/default/public/error/url-not-found.html @@ -0,0 +1,15 @@ + + + +
++ The requested URL was not found on this server. +
+ + + diff --git a/server.js b/server.js index db7ba9306..bc2a884c2 100644 --- a/server.js +++ b/server.js @@ -615,6 +615,12 @@ app.use('/api/backends/scale-alt', scaleAltRouter); app.use('/api/speech', speechRouter); app.use('/api/azure', azureRouter); +// If all other middlewares fail, send 404 error. +const notFoundWebpage = fs.readFileSync('./public/error/url-not-found.html', { encoding: 'utf-8' }); +app.use((req, res, next) => { + res.status(404).send(notFoundWebpage); +}); + const tavernUrlV6 = new URL( (cliArguments.ssl ? 'https://' : 'http://') + (listen ? '[::]' : '[::1]') +