#!/usr/bin/env node const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = process.env.PORT || 5173; const DIST_DIR = path.join(__dirname, '../memory-viewer/dist'); const mimeTypes = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpg', '.gif': 'image/gif', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.woff': 'font/woff', '.woff2': 'font/woff2', }; const server = http.createServer((req, res) => { let filePath = path.join(DIST_DIR, req.url === '/' ? 'index.html' : req.url); // Handle SPA routing - return index.html for non-file requests if (!fs.existsSync(filePath) && !req.url.startsWith('/api')) { filePath = path.join(DIST_DIR, 'index.html'); } const ext = path.extname(filePath); const contentType = mimeTypes[ext] || 'application/octet-stream'; fs.readFile(filePath, (err, content) => { if (err) { res.writeHead(404); res.end('Not found'); return; } res.writeHead(200, { 'Content-Type': contentType }); res.end(content); }); }); server.listen(PORT, '0.0.0.0', () => { console.log(`Memory Viewer frontend serving on http://0.0.0.0:${PORT}`); console.log(`Dist folder: ${DIST_DIR}`); });