#!/usr/bin/env node /* Tiny zero-dependency static server for Diablo2D. * node server.js [port] (default 8080) */ const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = parseInt(process.argv[2] || process.env.PORT || '8080', 10); const ROOT = __dirname; const MIME = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.json': 'application/json', '.webmanifest': 'application/manifest+json', '.png': 'image/png', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.md': 'text/plain; charset=utf-8', }; http.createServer((req, res) => { let urlPath = decodeURIComponent((req.url || '/').split('?')[0]); if (urlPath.endsWith('/')) urlPath += 'index.html'; const file = path.normalize(path.join(ROOT, urlPath)); if (!file.startsWith(ROOT)) { res.writeHead(403); return res.end('forbidden'); } fs.readFile(file, (err, data) => { if (err) { res.writeHead(404); return res.end('not found'); } res.writeHead(200, { 'Content-Type': MIME[path.extname(file)] || 'application/octet-stream', 'Cache-Control': 'no-cache', }); res.end(data); }); }).listen(PORT, () => console.log(`Diablo2D running → http://localhost:${PORT}`));