import { assets, slideCount, type Asset } from './assets.generated.ts' function body(asset: Asset): BodyInit { if (asset.text != null) return asset.text const bin = atob(asset.base64 ?? '') const bytes = new Uint8Array(bin.length) for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i) return bytes } function respond(path: string, method: string) { const asset = assets[path]! return new Response(method === 'HEAD' ? null : body(asset), { headers: { 'content-type': asset.type, 'cache-control': path === 'favicon.ico' ? 'public, max-age=3600' : 'no-cache', 'x-content-type-options': 'nosniff', }, }) } /** * The deck is two self-contained pages: the HyperFrames slideshow shell (index.html) and * the composition it plays in an iframe (composition.html), with fonts, images and scripts * inlined. Kody strips the package mount before forwarding; nothing here depends on it. */ export default { async fetch(request: Request): Promise { if (request.method !== 'GET' && request.method !== 'HEAD') { return new Response('Method not allowed', { status: 405 }) } const { pathname } = new URL(request.url) if (pathname.endsWith('/composition.html')) return respond('composition.html', request.method) if (pathname.endsWith('/favicon.ico')) return respond('favicon.ico', request.method) if (pathname.endsWith('/health')) return Response.json({ ok: true, slides: slideCount }) return respond('index.html', request.method) }, }