Skip to content

Commit 19fbe7a

Browse files
committed
Fix database
1 parent 1e1e20e commit 19fbe7a

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

worker/index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
export default {
22
async fetch(request, env) {
3-
const url = new URL(request.url);
4-
if (url.pathname.startsWith('/api/')) {
5-
return handleApi(request, url, env);
6-
}
7-
if (env.__STATIC_CONTENT) {
8-
return env.__STATIC_CONTENT.fetch(request);
3+
try {
4+
const url = new URL(request.url);
5+
if (url.pathname.startsWith('/api/')) {
6+
return await handleApi(request, url, env);
7+
}
8+
9+
const assetHandler = env.__STATIC_CONTENT || globalThis.__STATIC_CONTENT;
10+
if (assetHandler?.fetch) {
11+
try {
12+
return await assetHandler.fetch(request);
13+
} catch (error) {
14+
return new Response(JSON.stringify({ error: 'Static asset fetch failed', details: error.message }), { status: 500, headers: jsonHeaders() });
15+
}
16+
}
17+
18+
return new Response(JSON.stringify({ error: 'Static content not bound. Check your wrangler site configuration.' }), { status: 500, headers: jsonHeaders() });
19+
} catch (error) {
20+
return new Response(JSON.stringify({ error: 'Worker error', details: error.message }), { status: 500, headers: jsonHeaders() });
921
}
10-
return new Response(JSON.stringify({ error: 'Not found' }), { status: 404, headers: jsonHeaders() });
1122
}
1223
};
1324

0 commit comments

Comments
 (0)