Perlines/web/tools/serve.mjs
Aqua 7009089758 web: WebGL2 scenes, audio inputs, analysis state, page
Aurora disk (spectrum-to-mesh extrusion), burning-water spray (stateless
onset-driven particles), vector trails (Perlin curl paths). File, mic and
synthetic demo inputs; frame-time HUD and ?bench mode.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 18:55:36 +00:00

17 lines
1 KiB
JavaScript

// Dev server: `node tools/serve.mjs [port]`, serves web/ over http://localhost (mic needs a secure context; localhost qualifies).
import http from 'node:http';
import { readFile } from 'node:fs/promises';
import { extname, join, normalize } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = join(fileURLToPath(new URL('.', import.meta.url)), '..');
const types = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.json': 'application/json' };
const port = +(process.argv[2] || 8080);
http.createServer(async (req, res) => {
const p = normalize(decodeURIComponent(new URL(req.url, 'http://x').pathname)).replace(/^(\.\.[/\\])+/, '');
try {
const f = join(root, p.endsWith('/') ? p + 'index.html' : p);
if (!f.startsWith(root)) throw new Error('outside root');
res.writeHead(200, { 'content-type': types[extname(f)] || 'application/octet-stream' }).end(await readFile(f));
} catch { res.writeHead(404).end('not found'); }
}).listen(port, '127.0.0.1', () => console.log(`Perlines on http://localhost:${port}/`));