diff options
| author | Paul Buetow <paul@buetow.org> | 2026-01-25 21:08:29 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-01-25 21:08:29 +0200 |
| commit | d1941a802743a6314107968b2573cc0d742c35ae (patch) | |
| tree | d4a27ce160397ec2e05c2c2a3e268b783a317349 | |
| parent | 089888a18d10a4cf8eeacf1ad2b4535ed641268d (diff) | |
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 <noreply@anthropic.com>
| -rw-r--r-- | Justfile | 4 | ||||
| -rw-r--r-- | serve.js | 49 |
2 files changed, 51 insertions, 2 deletions
@@ -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}/`); +}); |
