Skip to content

Commit

Permalink
server: don't throw in async callback from index requests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brunnre8 committed Apr 21, 2024
1 parent 36cb75e commit 8eb398c
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions server/server.ts
Expand Up @@ -406,22 +406,20 @@ 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) => {
if (err) {
throw err;
}
fs.readFile(Utils.getFileFromRelativeToRoot("client/index.html.tpl"), "utf-8", (err, file) => {
if (err) {
log.error(`failed to server index request: ${err.name}, ${err.message}`);
res.sendStatus(500);
return;
}

const config: IndexTemplateConfiguration = {
...getServerConfiguration(),
...{cacheBust: Helper.getVersionCacheBust()},
};
const config: IndexTemplateConfiguration = {
...getServerConfiguration(),
...{cacheBust: Helper.getVersionCacheBust()},
};

res.send(_.template(file)(config));
}
);
res.send(_.template(file)(config));
});
}

function initializeClient(
Expand Down

0 comments on commit 8eb398c

Please sign in to comment.