server: don't throw in async callback from index requests

This was flagged as an issue by codeQL

> Server crash [High]
> The server of this route handler will terminate when an
> uncaught exception from this location escapes an
> asynchronous callback.
This commit is contained in:
Reto Brunner 2024-04-21 15:49:51 +02:00
parent 36cb75ee99
commit 8eb398c5cc

View file

@ -406,12 +406,11 @@ function forceNoCacheRequest(_req: Request, res: Response, next: NextFunction) {
function indexRequest(_req: Request, res: Response) {
res.setHeader("Content-Type", "text/html");
return fs.readFile(
Utils.getFileFromRelativeToRoot("client/index.html.tpl"),
"utf-8",
(err, file) => {
fs.readFile(Utils.getFileFromRelativeToRoot("client/index.html.tpl"), "utf-8", (err, file) => {
if (err) {
throw err;
log.error(`failed to server index request: ${err.name}, ${err.message}`);
res.sendStatus(500);
return;
}
const config: IndexTemplateConfiguration = {
@ -420,8 +419,7 @@ function indexRequest(_req: Request, res: Response) {
};
res.send(_.template(file)(config));
}
);
});
}
function initializeClient(