This repository was archived by the owner on Aug 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
62 lines (53 loc) · 1.61 KB
/
Copy pathserver.js
File metadata and controls
62 lines (53 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Simple HTTP server for local development
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = 8080;
const MIME_TYPES = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.gif': 'image/gif',
'.ico': 'image/x-icon'
};
const server = http.createServer((req, res) => {
console.log(`${req.method} ${req.url}`);
// Normalize URL path
let filePath = req.url;
if (filePath === '/') {
filePath = '/index.html';
}
// Map URL to local file path
filePath = path.join(__dirname, filePath);
// Get file extension
const extname = path.extname(filePath).toLowerCase();
// Determine content type
const contentType = MIME_TYPES[extname] || 'application/octet-stream';
// Read file
fs.readFile(filePath, (err, content) => {
if (err) {
if (err.code === 'ENOENT') {
// File not found
res.writeHead(404);
res.end('File not found');
} else {
// Server error
res.writeHead(500);
res.end(`Server Error: ${err.code}`);
}
} else {
// Success
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
});
});
server.listen(PORT, '0.0.0.0', () => {
console.log(`Server running at http://localhost:${PORT}/`);
console.log(`Server also available at http://127.0.0.1:${PORT}/`);
console.log(`If using WSL, try your Windows host IP address at port ${PORT}`);
console.log(`Open your browser to one of these URLs to use the Order Tracker`);
});