From 3c5f2727364bcfc75fd39e4478a0cfe850a1de9f Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 16 Apr 2024 00:01:28 +0200 Subject: allow 404 errors to be cached --- src/app.ts | 8 ++------ 1 file 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; 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) { -- cgit 1.4.1