const http = require('http'); const fs = require('fs'); const path = require('path'); const root = path.resolve(__dirname, '..', 'dist', 'frontend', 'browser'); const port = Number(process.env.PORT || 4301); const types = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.ico': 'image/x-icon' }; http.createServer((req, res) => { const urlPath = decodeURIComponent((req.url || '/').split('?')[0]); const candidate = path.join(root, urlPath === '/' ? 'index.html' : urlPath); const safePath = candidate.startsWith(root) && fs.existsSync(candidate) && fs.statSync(candidate).isFile() ? candidate : path.join(root, 'index.html'); res.setHeader('Content-Type', types[path.extname(safePath)] || 'application/octet-stream'); fs.createReadStream(safePath).pipe(res); }).listen(port, '127.0.0.1', () => { console.log(`Static preview ready: http://127.0.0.1:${port}`); });