Add hooks.server.ts for Workers for Platforms asset serving
Some checks failed
Deploy Site / deploy-chirho (push) Failing after 5s

This commit is contained in:
2026-01-13 04:50:04 +00:00
parent 35032fa988
commit bb5aeaec57

34
src/hooks.server.ts Normal file
View File

@@ -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