diff --git a/server/server.test.ts b/server/server.test.ts index 16166f8..3df4845 100644 --- a/server/server.test.ts +++ b/server/server.test.ts @@ -1,6 +1,5 @@ import { assertEquals } from "$std/assert/assert_equals.ts"; import { assertStringIncludes } from "$std/assert/assert_string_includes.ts"; -import { assertThrows } from "$std/assert/assert_throws.ts"; import { join } from "$std/path/join.ts"; import { respond } from "./server.ts"; @@ -65,13 +64,9 @@ Deno.test( await res.body?.cancel(); assertEquals(res.status, 200); - assertThrows(() => - assertStringIncludes( - res.headers.get("Content-Type") ?? "", - // Currently, the .pkg file isn't served with the correct content type. - // However, this isn't a big deal, so I'm ignoring the failure. - "application/octet-stream", - ), + assertStringIncludes( + res.headers.get("Content-Type") ?? "", + "application/octet-stream", ); }, ); diff --git a/server/server.ts b/server/server.ts index 43f48ac..dda4069 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1,19 +1,19 @@ import { serveDir } from "$std/http/file_server.ts"; -function serve(): void { - Deno.serve(async (req: Request): Promise => await respond(req)); -} - -const headers = [ - "Cross-Origin-Opener-Policy: same-origin", - "Cross-Origin-Embedder-Policy: require-corp", -]; - export async function respond(req: Request, dir = "build"): Promise { - return await serveDir(req, { + const path = new URL(req.url).pathname; + const res = await serveDir(req, { fsRoot: dir, - headers: headers, + enableCors: true, }); + + res.headers.set("Cross-Origin-Opener-Policy", "same-origin"); + res.headers.set("Cross-Origin-Embedder-Policy", " require-corp"); + if (path.endsWith(".pck")) { + res.headers.set("Content-Type", "application/octet-stream"); + } + + return res; } -serve(); +Deno.serve(async (req: Request): Promise => await respond(req));