智慧水务管理系统 - 精河县供水工程综合管理平台

serve-8080.js 634B

12345678910111213
  1. const http = require('http');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const PORT = process.env.FRONTEND_PORT || 8081;
  5. http.createServer((req, res) => {
  6. let filePath = path.join(__dirname, req.url === '/' ? 'index.html' : req.url);
  7. const ext = path.extname(filePath);
  8. const types = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript' };
  9. fs.readFile(filePath, (err, data) => {
  10. res.writeHead(err ? 404 : 200, { 'Content-Type': types[ext] || 'text/plain' });
  11. res.end(err ? 'Not Found' : data);
  12. });
  13. }).listen(PORT, () => console.log('前端已启动:http://localhost:' + PORT));