Skip to content

Commit edbeb4c

Browse files
committed
fix: route
1 parent 199fd07 commit edbeb4c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

public/_worker.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Cloudflare Workers script for SPA routing
2+
export default {
3+
async fetch(request, env, ctx) {
4+
const url = new URL(request.url);
5+
6+
// Try to serve the requested path first
7+
let response = await env.ASSETS.fetch(request);
8+
9+
// If the path doesn't exist (404), serve index.html instead
10+
// This enables client-side routing for SPA
11+
if (response.status === 404) {
12+
const indexUrl = new URL('/', request.url);
13+
response = await env.ASSETS.fetch(indexUrl);
14+
15+
// Return the index.html with 200 status for client-side routing
16+
return new Response(response.body, {
17+
status: 200,
18+
headers: response.headers
19+
});
20+
}
21+
22+
return response;
23+
}
24+
};

0 commit comments

Comments
 (0)