#!/usr/bin/env node /* Jamstack web relay (W2 / R4b) — dependency-free Node HTTP server. * * Gives a browser game the SAME .live// interface as desktop, so the * existing bin/eval, snapshot, query, tail-log, hot-reload work against a * browser tab: * - serves build/web/ (same-origin -> no CORS, no ws dep) and injects * \n')); } // no-store: the wasm/js are rebuilt often during dev; without this the // browser caches game.wasm aggressively (Emscripten's fetch is cached // separately from the HTML, so a hard-refresh doesn't bust it) and serves a // stale build -- making code changes appear to have "no effect". res.writeHead(200, { 'Content-Type': MIME[ext] || 'application/octet-stream', 'Cache-Control': 'no-store, no-cache, must-revalidate', }); res.end(body); }); } const server = http.createServer((req, res) => { const p = req.url.replace(/\?.*$/, ''); if (p === '/jamstack/poll') return handlePoll(res); if (p === '/jamstack/result') return readBody(req, (b) => { try { const o = JSON.parse(b || '{}'); const r = (o.result == null) ? '{}' : (typeof o.result === 'string' ? o.result : JSON.stringify(o.result)); writeAtomic(path.join(AGENT, 'result-' + o.id + '.json'), r); } catch (e) {} res.writeHead(204); res.end(); }); if (p === '/jamstack/console') return readBody(req, (b) => { try { const o = JSON.parse(b || '{}'); if (o.line != null) fs.appendFileSync(path.join(LIVE, 'game-console'), String(o.line) + '\n'); } catch (e) {} res.writeHead(204); res.end(); }); if (p === '/jamstack/status') return readBody(req, (b) => { try { const o = JSON.parse(b || '{}'); writeStatus(Object.assign({ connected: true, target: 'web', token: TOKEN }, o)); } catch (e) {} res.writeHead(204); res.end(); }); if (p === '/agent-bridge.js') { return fs.readFile(path.join(ROOT, 'web', 'agent-bridge.js'), (err, data) => { if (err) { res.writeHead(404); return res.end(); } res.writeHead(200, { 'Content-Type': 'text/javascript' }); res.end(data); }); } return serveStatic(res, p); }); server.listen(PORT, '0.0.0.0', () => { console.log('jamstack relay: http://localhost:' + PORT + ' -> ' + WEB); console.log(' .live mount: ' + LIVE); console.log(' bin: eval snapshot query tail-log hot-reload'); console.log(' open the URL in a browser, then: sh ' + path.join(BIN, 'eval') + " 'Rl.get_fps'"); });