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
This commit is contained in:
Spappz
2025-01-25 03:42:04 +00:00
parent 538d66191e
commit a5dc505e61
2 changed files with 21 additions and 0 deletions

View File

@ -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]') +