about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2023-09-16 08:08:43 +0200
committerAlan Pearce2023-09-16 08:08:43 +0200
commit135319739943f4f036f77a70db2a96d4249bbd43 (patch)
tree543cced2b26dbdcfe1f3536ffcf1914fe7d4958d
parent89d211a3cc537aaba08667ebd0c16cd2a54ec960 (diff)
downloadwebsite-135319739943f4f036f77a70db2a96d4249bbd43.tar.lz
website-135319739943f4f036f77a70db2a96d4249bbd43.tar.zst
website-135319739943f4f036f77a70db2a96d4249bbd43.zip
Override content-type for /feed-styles/
-rw-r--r--src/index.ts11
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");