GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — writeitdownripitup/server.mjs at main · HazzJC/writeitdownripitup Expand file tree/ Copy pathserver.mjsMore file actions 56 lines (53 loc) · 1.82 KB / Copy pathserver.mjsFile metadata and controls56 lines (53 loc) · 1.82 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 // Minimal static server. ES modules need http://, so file:// will not do. // Usage: node server.mjs [port] import { createServer } from 'node:http'; import { readFile, stat } from 'node:fs/promises'; import { join, extname, normalize } from 'node:path'; import { fileURLToPath } from 'node:url'; const ROOT = fileURLToPath(new URL('.', import.meta.url)); const PORT = Number(process.argv[2]) || 5173; const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.json': 'application/json; charset=utf-8', '.svg': 'image/svg+xml', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.webp': 'image/webp', '.woff2': 'font/woff2', '.woff': 'font/woff', '.ttf': 'font/ttf', '.ico': 'image/x-icon', '.md': 'text/markdown; charset=utf-8', }; createServer(async (req, res) => { try { let path = decodeURIComponent(new URL(req.url, 'http://x').pathname); if (path.endsWith('/')) path += 'index.html'; // Keep requests inside the project directory. const full = join(ROOT, normalize(path).replace(/^(\.\.[/\\])+/, '')); if (!full.startsWith(ROOT)) { res.writeHead(403).end('forbidden'); return; } const info = await stat(full); if (info.isDirectory()) { res.writeHead(302, { Location: path + '/' }).end(); return; } const body = await readFile(full); res.writeHead(200, { 'Content-Type': TYPES[extname(full).toLowerCase()] || 'application/octet-stream', 'Content-Length': body.length, 'Cache-Control': 'no-cache', }); res.end(body); } catch (err) { res.writeHead(err.code === 'ENOENT' ? 404 : 500).end(String(err.code || err)); } }).listen(PORT, () => { console.log(`Ritual -> http://localhost:${PORT}`); }); |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |