From bb5aeaec57e0c87af6fe8300d466846f7361042b Mon Sep 17 00:00:00 2001 From: LoveJesus Date: Tue, 13 Jan 2026 04:50:04 +0000 Subject: [PATCH] Add hooks.server.ts for Workers for Platforms asset serving --- src/hooks.server.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/hooks.server.ts diff --git a/src/hooks.server.ts b/src/hooks.server.ts new file mode 100644 index 0000000..c6e4838 --- /dev/null +++ b/src/hooks.server.ts @@ -0,0 +1,34 @@ +// For God so loved the world — John 3:16 + +import type { Handle } from '@sveltejs/kit'; + +/** + * Server hooks for Workers for Platforms compatibility + * In dispatch namespaces, static assets are not automatically served, + * so we need to explicitly handle them using the ASSETS binding + */ +export const handle: Handle = async ({ event, resolve }) => { + const { request, platform } = event; + const url = new URL(request.url); + + // Check if this is a static asset request (/_app/ path or known static extensions) + const isStaticAssetChirho = url.pathname.startsWith('/_app/') || + url.pathname.match(/\.(js|css|woff2?|ttf|eot|png|jpg|jpeg|gif|svg|ico|webp|avif)$/i); + + if (isStaticAssetChirho && platform?.env?.ASSETS) { + try { + // Forward to the ASSETS binding + const responseChirho = await platform.env.ASSETS.fetch(request); + if (responseChirho.status \!== 404) { + return responseChirho; + } + } catch (errChirho) { + console.error('[Hooks] Failed to fetch from ASSETS:', errChirho); + } + } + + // Fall through to normal SvelteKit handling + return resolve(event); +}; + +// JESUS CHRIST IS LORD \ No newline at end of file