-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
32 lines (30 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const server = Bun.serve({
async fetch(req) {
const path = new URL(req.url).pathname;
if (req.method === "POST" && path === "/csp-report") {
const data = await req.json();
console.log("Received JSON:", data);
return Response.json({ success: true, data });
}
if (path === "/csp-no-violation") {
// These header will not generate any violation report
return new Response(Bun.file("./index.html"), {
headers: {
"Content-Security-Policy": "script-src 'nonce-abc';",
"Content-Security-Policy-Report-Only":
"script-src 'nonce-abc'; report-uri /csp-report;",
},
});
}
// These header will generate a violation report
return new Response(Bun.file("./index.html"), {
headers: {
"Content-Security-Policy":
"script-src 'self' 'unsafe-inline' https://*.cloudflare.com:*;",
"Content-Security-Policy-Report-Only":
"script-src 'nonce-abc'; report-uri /csp-report;",
},
});
},
});
console.log(`Listening on ${server.url}`);