import { createReadStream, existsSync, statSync } from 'node:fs'; import { createServer } from 'node:http'; import { extname, join, normalize } from 'node:path'; const root = process.cwd(); const port = Number(process.env.PORT || 4173); const mime = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.json': 'application/json; charset=utf-8', '.png': 'image/png' }; createServer((req, res) => { const raw = decodeURIComponent((req.url || '/').split('?')[0]); const safe = normalize(raw).replace(/^(\.\.[/\\])+/, ''); let file = join(root, safe === '/' ? '/web/index.html' : safe); if (existsSync(file) && statSync(file).isDirectory()) file = join(file, 'index.html'); if (!existsSync(file)) { res.writeHead(404); res.end('Not found'); return; } res.writeHead(200, { 'content-type': mime[extname(file)] || 'application/octet-stream' }); createReadStream(file).pipe(res); }).listen(port, () => { console.log(`Steel Assault Rift preview: http://localhost:${port}/web/index.html`); });