#!/usr/bin/env bun // Static server for the demo game's web build. bun examples/demo-game/serve.ts [--port 8740] const i = process.argv.indexOf('--port'); const port = Number(i > 0 ? process.argv[i + 1] : process.env.PORT ?? 8740); const root = new URL('./web/', import.meta.url).pathname; const TYPES: Record = { html: 'text/html; charset=utf-8', js: 'text/javascript; charset=utf-8', css: 'text/css' }; const server = Bun.serve({ port, hostname: '127.0.0.1', async fetch(req) { let p = decodeURIComponent(new URL(req.url).pathname); if (p.endsWith('/')) p += 'index.html'; if (p.includes('..')) return new Response('no', { status: 400 }); const f = Bun.file(root + p.slice(1)); if (!(await f.exists())) return new Response('not found', { status: 404 }); return new Response(f, { headers: { 'content-type': TYPES[p.split('.').pop() ?? ''] ?? 'application/octet-stream', 'cache-control': 'no-store' } }); }, }); console.log(`Prism Puddle demo on http://127.0.0.1:${server.port}/`);