#!/usr/bin/env node /** * Simple static file server for development */ const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = process.argv[2] || 9000; const MIME_TYPES = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', '.json': 'application/json', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.md': 'text/markdown', '.ico': 'image/x-icon' }; const server = http.createServer((req, res) => { let filePath = '.' + (req.url === '/' ? '/index.html' : req.url); filePath = decodeURIComponent(filePath); const ext = path.extname(filePath).toLowerCase(); const contentType = MIME_TYPES[ext] || 'application/octet-stream'; fs.readFile(filePath, (err, content) => { if (err) { if (err.code === 'ENOENT') { res.writeHead(404); res.end('Not found'); } else { res.writeHead(500); res.end('Server error'); } } else { res.writeHead(200, { 'Content-Type': contentType }); res.end(content); } }); }); server.listen(PORT, () => { console.log(`Server running at http://localhost:${PORT}/`); });