first-test/server.js
edo e896912c04 Add mobile-friendly web Snake game on port 10000
Node.js HTTP server serving a canvas Snake game optimised for phones:
inline onclick handlers for reliable touch, swipe support, big d-pad,
no-cache headers, and responsive canvas sizing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 22:52:29 +00:00

38 lines
845 B
JavaScript

#!/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}`);
});