Skip to content

Commit e5f07ee

Browse files
authored
fix(giscus): use worker script for CORS headers (#36)
1 parent 4a85bad commit e5f07ee

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/worker.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default {
2+
async fetch(request: Request, env: { ASSETS: Fetcher }): Promise<Response> {
3+
const url = new URL(request.url);
4+
5+
// Serve assets from the dist directory
6+
const response = await env.ASSETS.fetch(request);
7+
8+
// Add CORS header for giscus theme CSS
9+
if (url.pathname === '/giscus-theme.css') {
10+
const newHeaders = new Headers(response.headers);
11+
newHeaders.set('Access-Control-Allow-Origin', 'https://giscus.app');
12+
return new Response(response.body, {
13+
status: response.status,
14+
statusText: response.statusText,
15+
headers: newHeaders,
16+
});
17+
}
18+
19+
return response;
20+
},
21+
};

wrangler.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name = "codingwithcalvin-net"
22
compatibility_date = "2024-12-01"
3+
main = "src/worker.ts"
34

45
[assets]
56
directory = "./dist"
7+
binding = "ASSETS"

0 commit comments

Comments
 (0)