From d1941a802743a6314107968b2573cc0d742c35ae Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 25 Jan 2026 21:08:29 +0200 Subject: Use Node.js for webserver instead of Python Added serve.js - simple static file server using Node's http module. Updated Justfile to use node serve.js for consistency. Co-Authored-By: Claude Opus 4.5 --- Justfile | 4 ++-- serve.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 serve.js diff --git a/Justfile b/Justfile index 43861c8..33a04dc 100644 --- a/Justfile +++ b/Justfile @@ -9,10 +9,10 @@ build: # Start webserver and open in Firefox open: - python -m http.server 9000 & + node serve.js 9000 & sleep 1 firefox http://localhost:9000 # Stop the webserver stop: - pkill -f "http.server 9000" || true + pkill -f "node serve.js" || true diff --git a/serve.js b/serve.js new file mode 100644 index 0000000..9e71f46 --- /dev/null +++ b/serve.js @@ -0,0 +1,49 @@ +#!/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}/`); +}); -- cgit v1.2.3