| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- const http = require('http');
- const fs = require('fs');
- const path = require('path');
- const PORT = 8888;
- const DIST_DIR = 'd:\\AI开发\\DRG医保控费预警系统开发项目\\frontend\\dist';
- const mimeTypes = {
- '.html': 'text/html',
- '.js': 'application/javascript',
- '.css': 'text/css',
- '.json': 'application/json',
- '.png': 'image/png',
- '.jpg': 'image/jpeg',
- '.svg': 'image/svg+xml',
- '.ico': 'image/x-icon'
- };
- const server = http.createServer((req, res) => {
- console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);
-
- let filePath = path.join(DIST_DIR, req.url === '/' ? 'index.html' : req.url);
-
- // Check if file exists
- if (!fs.existsSync(filePath)) {
- res.writeHead(404);
- res.end('File not found');
- return;
- }
-
- const ext = path.extname(filePath).toLowerCase();
- const contentType = mimeTypes[ext] || 'application/octet-stream';
-
- fs.readFile(filePath, (err, content) => {
- if (err) {
- res.writeHead(500);
- res.end('Server error');
- return;
- }
- res.writeHead(200, { 'Content-Type': contentType });
- res.end(content);
- });
- });
- server.listen(PORT, () => {
- console.log(`Server running at http://localhost:${PORT}/`);
- });
|