// A tiny static server for playing the built game: `node build.mjs && node serve.mjs`, then // open http://127.0.0.1:8851. ES modules need http, not file://. It sends no-store so a rebuild // is never hidden behind a cached module. import { createReadStream, statSync } from "node:fs"; import { createServer } from "node:http"; import { extname, join, normalize } from "node:path"; const root = join(process.cwd(), "dist"); const port = Number(process.env.PORT) || 8851; const types = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".json": "application/json", ".png": "image/png", ".svg": "image/svg+xml" }; createServer((req, res) => { const path = normalize(decodeURIComponent(new URL(req.url, "http://x").pathname)).replace(/^(\.\.[/\\])+/, ""); let file = join(root, path); try { if (statSync(file).isDirectory()) file = join(file, "index.html"); statSync(file); } catch { res.writeHead(404).end("not found"); return; } res.writeHead(200, { "content-type": types[extname(file)] ?? "application/octet-stream", "cache-control": "no-store" }); createReadStream(file).pipe(res); }).listen(port, "127.0.0.1", () => console.log(`Claudia on http://127.0.0.1:${port}`));