/* zero-dependency static server with aggressive no-caching */ const http = require('http'); const fs = require('fs'); const path = require('path'); const ROOT = __dirname; const MIME = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.png': 'image/png', '.ico': 'image/x-icon', '.json': 'application/json' }; http.createServer((req, res) => { let p = decodeURIComponent((req.url || '/').split('?')[0]); if (p === '/') p = '/index.html'; const file = path.normalize(path.join(ROOT, p)); if (!file.startsWith(ROOT)) { res.writeHead(403); return res.end(); } fs.readFile(file, (err, data) => { if (err) { res.writeHead(404, { 'Cache-Control': 'no-store' }); return res.end('not found'); } res.writeHead(200, { 'Content-Type': MIME[path.extname(file)] || 'application/octet-stream', 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0' }); res.end(data); }); }).listen(8917, '127.0.0.1', () => console.log('wulin serving on http://127.0.0.1:8917 (no-store)'));