We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 199fd07 commit edbeb4cCopy full SHA for edbeb4c
public/_worker.js
@@ -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