fix: The "Made with Fresh" Badge broke (#970)

This commit is contained in:
hashrock
2023-01-07 23:17:52 +09:00
committed by GitHub
parent 8802336d09
commit d8c8a9daf3
4 changed files with 46 additions and 9 deletions
+4
View File
@@ -30,3 +30,7 @@ jobs:
- name: Type check website
run: deno check main.ts dev.ts
working-directory: www/
- name: Run tests
run: deno test -A
working-directory: www/
+5
View File
@@ -9,5 +9,10 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"test": {
"files": {
"exclude": ["www/"]
}
}
}
+37
View File
@@ -0,0 +1,37 @@
import { assertEquals } from "$std/testing/asserts.ts";
import { TextLineStream } from "$std/streams/delimiter.ts";
Deno.test("CORS should not set on GET /fresh-badge.svg", {
sanitizeResources: false,
}, async () => {
const serverProcess = Deno.run({
cmd: ["deno", "run", "-A", "./main.ts"],
stdin: "null",
stdout: "piped",
stderr: "inherit",
});
const decoder = new TextDecoderStream();
const lines = serverProcess.stdout.readable
.pipeThrough(decoder)
.pipeThrough(new TextLineStream());
let started = false;
for await (const line of lines) {
if (line.includes("Listening on http://")) {
started = true;
break;
}
}
if (!started) {
throw new Error("Server didn't start up");
}
const res = await fetch("http://localhost:8000/fresh-badge.svg");
await res.body?.cancel();
assertEquals(res.headers.get("cross-origin-resource-policy"), null);
await lines.cancel();
serverProcess.kill("SIGTERM");
serverProcess.close();
});
-9
View File
@@ -76,15 +76,6 @@ export async function handler(
try {
const resp = await ctx.next();
const headers = new Headers(resp.headers);
headers.set(
"Strict-Transport-Security",
"max-age=63072000; includeSubDomains; preload",
);
headers.set("X-Content-Type-Options", "nosniff");
headers.set("X-Frame-Options", "DENY");
headers.set("Cross-Origin-Resource-Policy", "same-origin");
headers.set("Cross-Origin-Opener-Policy", "same-origin");
headers.set("Cross-Origin-Embedder-Policy", "same-origin");
res = new Response(resp.body, { status: resp.status, headers });
return res;
} catch (e) {