diff options
author | Alan Pearce | 2023-09-16 08:08:43 +0200 |
---|---|---|
committer | Alan Pearce | 2023-09-16 08:08:43 +0200 |
commit | 135319739943f4f036f77a70db2a96d4249bbd43 (patch) | |
tree | 543cced2b26dbdcfe1f3536ffcf1914fe7d4958d | |
parent | 89d211a3cc537aaba08667ebd0c16cd2a54ec960 (diff) | |
download | website-135319739943f4f036f77a70db2a96d4249bbd43.tar.lz website-135319739943f4f036f77a70db2a96d4249bbd43.tar.zst website-135319739943f4f036f77a70db2a96d4249bbd43.zip |
Override content-type for /feed-styles/
-rw-r--r-- | src/index.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/index.ts b/src/index.ts index d4c7b3d..7a2c5f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,7 @@ type File = { handle: BunFile; relPath: string; headers?: Record<string, string>; + type: string; size: number; mtime: Date; }; @@ -67,10 +68,12 @@ function registerFile( if (files.get(pathname) !== undefined) { console.warn("File already registered:", pathname); } + const handle = Bun.file(filename); files.set(pathname, { filename, relPath: "/" + path, - handle: Bun.file(filename), + handle: handle, + type: pathname.startsWith("/feed-styles") ? "text/xsl" : handle.type, headers: pathname === "/404.html" ? Object.assign({}, defaultHeaders, { "cache-control": "no-cache" }) @@ -185,7 +188,7 @@ const server = Bun.serve({ span.setTag("http.status_code", 200); return serveFile(files.get(file.relPath + ".br"), 200, { "content-encoding": "br", - "content-type": file.handle.type, + "content-type": file.type, }); } else if ( encodings.includes("zstd") && @@ -195,7 +198,7 @@ const server = Bun.serve({ span.setTag("http.status_code", 200); return serveFile(files.get(file.relPath + ".zst"), 200, { "content-encoding": "zstd", - "content-type": file.handle.type, + "content-type": file.type, }); } else if ( encodings.includes("gzip") && @@ -205,7 +208,7 @@ const server = Bun.serve({ span.setTag("http.status_code", 200); return serveFile(files.get(file.relPath + ".gz"), 200, { "content-encoding": "gzip", - "content-type": file.handle.type, + "content-type": file.type, }); } span.setTag("http.encoding", "identity"); |