diff options
author | Alan Pearce | 2024-04-16 00:01:28 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-16 00:01:28 +0200 |
commit | 3c5f2727364bcfc75fd39e4478a0cfe850a1de9f (patch) | |
tree | e5375772559e2d618753c329675ab03c4a81f172 /src | |
parent | a1f49f7be3189c083f6d69f6939cd092ed54ff90 (diff) | |
download | website-3c5f2727364bcfc75fd39e4478a0cfe850a1de9f.tar.lz website-3c5f2727364bcfc75fd39e4478a0cfe850a1de9f.tar.zst website-3c5f2727364bcfc75fd39e4478a0cfe850a1de9f.zip |
allow 404 errors to be cached
Diffstat (limited to 'src')
-rw-r--r-- | src/app.ts | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/app.ts b/src/app.ts index 8d08e0b..7d5e448 100644 --- a/src/app.ts +++ b/src/app.ts @@ -34,7 +34,6 @@ type File = { filename: string; handle: BunFile; relPath: string; - headers?: Record<string, string>; type: string; size: number; mtime: Date; @@ -80,10 +79,6 @@ async function registerFile( relPath: "/" + path, handle: handle, type: pathname.startsWith("/feed-styles.xsl") ? "text/xsl" : handle.type, - headers: - pathname === "/404.html" - ? Object.assign({}, defaultHeaders, { "cache-control": "no-cache" }) - : undefined, size: stat.size, mtime: stat.mtime, etag: `W/"${await hashFile(handle)}"`, @@ -116,7 +111,7 @@ async function serveFile( headers: { "last-modified": file.mtime.toUTCString(), ...extraHeaders, - ...(file.headers || defaultHeaders), + ...defaultHeaders, }, status: statusCode, }); @@ -238,6 +233,7 @@ export const server = { if (!request.headers.get("accept")?.split(",").includes("text/html")) { return new Response("404 Not Found", { status, + headers: defaultHeaders, }); } if (notfound) { |