// Lightweight static file server for Reaktor modular synth const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = process.env.PORT || 80; const STATIC_DIR = path.join(__dirname, 'dist'); const MIME = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', '.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.woff2': 'font/woff2', '.wasm': 'application/wasm', }; const server = http.createServer((req, res) => { let filePath = path.join(STATIC_DIR, req.url === '/' ? 'index.html' : req.url); // SPA fallback: if file doesn't exist, serve index.html if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) { filePath = path.join(STATIC_DIR, 'index.html'); } if (!filePath.startsWith(STATIC_DIR)) { res.writeHead(403); res.end('Forbidden'); return; } const ext = path.extname(filePath).toLowerCase(); const contentType = MIME[ext] || 'application/octet-stream'; fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(err.code === 'ENOENT' ? 404 : 500); res.end(err.code === 'ENOENT' ? 'Not found' : 'Server error'); return; } if (['.png', '.jpg', '.woff2', '.js', '.css'].includes(ext)) { res.setHeader('Cache-Control', 'public, max-age=604800'); } res.writeHead(200, { 'Content-Type': contentType }); res.end(data); }); }); server.listen(PORT, () => { console.log(`[reaktor] Running on port ${PORT}`); });