소스 검색

fix(server): add Content-Type headers for proxied static assets (#6587)

Tom 1 개월 전
부모
커밋
dc8586371c
1개의 변경된 파일33개의 추가작업 그리고 1개의 파일을 삭제
  1. 33 1
      packages/opencode/src/server/server.ts

+ 33 - 1
packages/opencode/src/server/server.ts

@@ -2657,12 +2657,44 @@ export namespace Server {
         },
       )
       .all("/*", async (c) => {
-        return proxy(`https://app.opencode.ai${c.req.path}`, {
+        const path = c.req.path
+        const response = await proxy(`https://app.opencode.ai${path}`, {
           ...c.req,
           headers: {
             host: "app.opencode.ai",
           },
         })
+        // Cloudflare doesn't return Content-Type for static assets, so we need to add it
+        const mimeTypes: Record<string, string> = {
+          ".js": "application/javascript",
+          ".mjs": "application/javascript",
+          ".css": "text/css",
+          ".json": "application/json",
+          ".wasm": "application/wasm",
+          ".svg": "image/svg+xml",
+          ".png": "image/png",
+          ".jpg": "image/jpeg",
+          ".jpeg": "image/jpeg",
+          ".gif": "image/gif",
+          ".ico": "image/x-icon",
+          ".webp": "image/webp",
+          ".woff": "font/woff",
+          ".woff2": "font/woff2",
+          ".ttf": "font/ttf",
+          ".eot": "application/vnd.ms-fontobject",
+        }
+        for (const [ext, mime] of Object.entries(mimeTypes)) {
+          if (path.endsWith(ext)) {
+            const headers = new Headers(response.headers)
+            headers.set("Content-Type", mime)
+            return new Response(response.body, {
+              status: response.status,
+              statusText: response.statusText,
+              headers,
+            })
+          }
+        }
+        return response
       }),
   )