@@ -19,8 +19,20 @@ export default {
1919 // Handle root redirect to listRegistry.json
2020 if ( url . pathname === '/' ) {
2121 const redirectUrl = new URL ( '/listRegistry.json' , url . origin ) ;
22- const response = await env . ASSETS ?. fetch ( new Request ( redirectUrl , request ) ) ||
23- await fetch ( redirectUrl ) ;
22+ let response ;
23+
24+ try {
25+ // Try to fetch from assets first
26+ if ( env . ASSETS ) {
27+ response = await env . ASSETS . fetch ( new Request ( redirectUrl , request ) ) ;
28+ } else {
29+ response = await fetch ( redirectUrl ) ;
30+ }
31+ } catch ( error ) {
32+ console . error ( 'Error fetching listRegistry.json:' , error ) ;
33+ // Fallback to direct fetch
34+ response = await fetch ( redirectUrl ) ;
35+ }
2436
2537 return new Response ( response . body , {
2638 status : response . status ,
@@ -36,7 +48,17 @@ export default {
3648 }
3749
3850 // For all other requests, fetch from static assets and add CORS headers
39- const response = await env . ASSETS ?. fetch ( request ) || await fetch ( request ) ;
51+ let response ;
52+ try {
53+ if ( env . ASSETS ) {
54+ response = await env . ASSETS . fetch ( request ) ;
55+ } else {
56+ response = await fetch ( request ) ;
57+ }
58+ } catch ( error ) {
59+ console . error ( 'Error fetching asset:' , error ) ;
60+ response = await fetch ( request ) ;
61+ }
4062
4163 // Clone the response to add CORS headers
4264 const newResponse = new Response ( response . body , {
0 commit comments