Clean up dead toolbox code and harden routing and static serving
This commit is contained in:
parent
184314d913
commit
cce3f3c7f8
9 changed files with 25 additions and 98 deletions
10
server.mjs
10
server.mjs
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue