diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..d228cbf --- /dev/null +++ b/public/index.html @@ -0,0 +1,329 @@ + + + + + + Snake + + + + +

SNAKE

+ +
+
SCORE 0
+
BEST  0
+
+ +
+ +
+

SNAKE

+

tap to start

+ +
+
+ +
+
+ +
+ +
+ +
+ +
+
+ + + + diff --git a/server.js b/server.js new file mode 100644 index 0000000..01d4559 --- /dev/null +++ b/server.js @@ -0,0 +1,37 @@ +#!/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}`); +});