const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = process.env.FRONTEND_PORT || 8080; const server = http.createServer((req, res) => { let filePath = path.join(__dirname, req.url === '/' ? 'index.html' : req.url); const ext = path.extname(filePath); const contentTypes = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml' }; fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(404); res.end('Not Found'); } else { res.writeHead(200, { 'Content-Type': contentTypes[ext] || 'text/plain' }); res.end(data); } }); }); server.listen(PORT, () => { console.log(`🚀 前端服务已启动:http://localhost:${PORT}`); });