Check that path exists before serving

This commit is contained in:
Cohee 2024-04-27 21:54:28 +03:00
parent 1bcdc2652c
commit 3b153a6c9b
1 changed files with 5 additions and 1 deletions

View File

@ -612,9 +612,13 @@ function createRouteHandler(directoryFn) {
try {
const directory = directoryFn(req);
const filePath = decodeURIComponent(req.params[0]);
const exists = fs.existsSync(path.join(directory, filePath));
if (!exists) {
return res.sendStatus(404);
}
return res.sendFile(filePath, { root: directory });
} catch (error) {
return res.sendStatus(404);
return res.sendStatus(500);
}
};
}