allow 404 errors to be cached
Alan Pearce alan@alanpearce.eu
Tue, 16 Apr 2024 00:01:28 +0200
1 files changed, 2 insertions(+), 6 deletions(-)
jump to
M src/app.ts → 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 @@ filename, 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 @@ return new Response(await file.handle.arrayBuffer(), { headers: { "last-modified": file.mtime.toUTCString(), ...extraHeaders, - ...(file.headers || defaultHeaders), + ...defaultHeaders, }, status: statusCode, }); @@ -238,6 +233,7 @@ const notfound = files.get("/404.html"); if (!request.headers.get("accept")?.split(",").includes("text/html")) { return new Response("404 Not Found", { status, + headers: defaultHeaders, }); } if (notfound) {