const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = 8080; const ROOT = path.join(__dirname, 'Carrot_Hunter'); const MIME_TYPES = { '.html': 'text/html', '.js': 'application/javascript', '.css': 'text/css', '.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpeg', '.gif': 'image/gif', '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.svg': 'image/svg+xml', '.pdf': 'application/pdf', '.doc': 'application/msword' }; const server = http.createServer((req, res) => { console.log(`${req.method} ${req.url}`); // CORS headers res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); res.setHeader('Cache-Control', 'no-cache'); if (req.method === 'OPTIONS') { res.writeHead(200); res.end(); return; } let filePath = path.join(ROOT, req.url === '/' ? 'index.html' : req.url); const extname = String(path.extname(filePath)).toLowerCase(); const contentType = MIME_TYPES[extname] || 'application/octet-stream'; fs.readFile(filePath, (error, content) => { if (error) { if(error.code == 'ENOENT') { res.writeHead(404, { 'Content-Type': 'text/html' }); res.end('