const http = require('http'); const fs = require('fs'); const path = require('path'); const server = http.createServer((req, res) => { let p = path.join('./dist/build/h5', req.url === '/' ? 'index.html' : req.url); fs.readFile(p, (err, data) => { if (err) { res.writeHead(404); res.end('Not Found'); } else { const ext = path.extname(p); const types = { '.html': 'text/html', '.js': 'application/javascript', '.css': 'text/css', '.png': 'image/png', '.jpg': 'image/jpeg', '.json': 'application/json' }; res.writeHead(200, { 'Content-Type': types[ext] || 'application/octet-stream' }); res.end(data); } }); }); server.listen(8080, () => { console.log('Server running on http://localhost:8080'); });