fix: The "Made with Fresh" Badge broke (#970)
This commit is contained in:
@@ -30,3 +30,7 @@ jobs:
|
|||||||
- name: Type check website
|
- name: Type check website
|
||||||
run: deno check main.ts dev.ts
|
run: deno check main.ts dev.ts
|
||||||
working-directory: www/
|
working-directory: www/
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: deno test -A
|
||||||
|
working-directory: www/
|
||||||
|
|||||||
@@ -9,5 +9,10 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "preact"
|
"jsxImportSource": "preact"
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"files": {
|
||||||
|
"exclude": ["www/"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
@@ -76,15 +76,6 @@ export async function handler(
|
|||||||
try {
|
try {
|
||||||
const resp = await ctx.next();
|
const resp = await ctx.next();
|
||||||
const headers = new Headers(resp.headers);
|
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 });
|
res = new Response(resp.body, { status: resp.status, headers });
|
||||||
return res;
|
return res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user