Clean up dead toolbox code and harden routing and static serving

This commit is contained in:
Shinuwa 2026-09-09 15:52:17 +02:00
parent 184314d913
commit cce3f3c7f8
9 changed files with 25 additions and 98 deletions

View file

@ -67,7 +67,7 @@ function resolvePath(url) {
const publicCandidate = fileIfReadable(resolve(publicRoot, `.${requested}`));
if (publicCandidate && isInsideRoot(publicRoot, publicCandidate)) return publicCandidate;
return join(root, "index.html");
return extname(requested) ? null : join(root, "index.html");
}
const server = createServer((req, res) => {
@ -78,9 +78,15 @@ const server = createServer((req, res) => {
return;
}
const extension = extname(file);
const cacheControl = extension === ".html"
? "no-store"
: extension === ".json"
? "no-cache"
: "public, max-age=31536000, immutable";
res.writeHead(200, {
"Content-Type": types[extname(file)] || "application/octet-stream",
"Cache-Control": "no-store"
"Cache-Control": cacheControl
});
createReadStream(file).pipe(res);
});