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

crm-frontend.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const http = require('http');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const PORT = 8081;
  5. const server = http.createServer((req, res) => {
  6. let filePath = path.join(__dirname, req.url === '/' ? 'index.html' : req.url);
  7. const ext = path.extname(filePath);
  8. const contentTypes = {
  9. '.html': 'text/html',
  10. '.css': 'text/css',
  11. '.js': 'application/javascript',
  12. '.png': 'image/png',
  13. '.jpg': 'image/jpeg',
  14. '.gif': 'image/gif',
  15. '.svg': 'image/svg+xml',
  16. '.ico': 'image/x-icon'
  17. };
  18. console.log(`[${new Date().toISOString()}] 请求:${req.url} -> ${filePath}`);
  19. fs.readFile(filePath, (err, data) => {
  20. if (err) {
  21. console.error(`文件读取失败:${filePath}`);
  22. res.writeHead(404, { 'Content-Type': 'text/html' });
  23. res.end('<h1>404 - 文件未找到</h1>');
  24. } else {
  25. const contentType = contentTypes[ext] || 'application/octet-stream';
  26. console.log(`文件读取成功:${filePath} (${contentType})`);
  27. res.writeHead(200, { 'Content-Type': contentType });
  28. res.end(data);
  29. }
  30. });
  31. });
  32. server.listen(PORT, () => {
  33. console.log(`================================`);
  34. console.log(`🚀 中小企业 CRM 前端服务已启动`);
  35. console.log(`📡 端口:${PORT}`);
  36. console.log(`🌐 访问地址:http://localhost:${PORT}`);
  37. console.log(`📁 文件目录:${__dirname}`);
  38. console.log(`================================`);
  39. });
  40. server.on('error', (err) => {
  41. console.error(`服务器错误:${err.message}`);
  42. process.exit(1);
  43. });