diff --git a/src/server/Server.ts b/src/server/Server.ts index d0974f9..9502842 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -268,9 +268,10 @@ class Server extends EventEmitter { } // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars - #logError (err: Error, _req: Request, res: Response, _next: NextFunction) { + #logError (err: Error, req: Request, res: Response, _next: NextFunction) { this.#logger.error(`Unhandled error:\n${err.stack || err}`); - res.status(500).send('An internal error was encountered'); + if (!req.complete) + res.status(500).send('An internal error was encountered'); } #logRequest (req: Request, res: Response, next: NextFunction) { @@ -295,7 +296,7 @@ class Server extends EventEmitter { this.#_ready = false; // Close http server first and allow it to finish serving requests - if (this.#_server) + if (this.#_server) { this.#_server.close(async () => { await this.#_mongodb.close(); await this.#_mariadb.close(); @@ -306,7 +307,8 @@ class Server extends EventEmitter { this.#logger.status('Server shutdown complete.'); // eslint-disable-next-line no-process-exit process.exit(); - }); + }); + } } diff --git a/src/server/endpoints/pages/Home.ts b/src/server/endpoints/pages/Home.ts index c03ba16..bff250a 100644 --- a/src/server/endpoints/pages/Home.ts +++ b/src/server/endpoints/pages/Home.ts @@ -35,7 +35,7 @@ class Home extends Endpoint { async home (_req: Request, res: Response) { if (this.server.serveFiles && existsSync(path.join(this.server.serveFiles, '/build/index.html'))) - res.sendFile('/build/index.html', { root: this.server.serveFiles }); + return res.sendFile('/build/index.html', { root: this.server.serveFiles }); return res.status(404).end(); }