#!/usr/bin/env node 'use strict'; const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = 10000; const MIME = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.ico': 'image/x-icon', }; const server = http.createServer((req, res) => { let filePath = req.url === '/' ? '/index.html' : req.url; filePath = path.join(__dirname, 'public', filePath); const ext = path.extname(filePath); const mime = MIME[ext] || 'text/plain'; fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(404); res.end('Not found'); return; } res.writeHead(200, { 'Content-Type': mime, 'Cache-Control': 'no-store' }); res.end(data); }); }); server.listen(PORT, () => { console.log(`Snake running at http://localhost:${PORT}`); });