Files

19 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

/* Throwaway static server so the operator-page preview can be looked at in a
browser. Absolute root, no reliance on cwd — the launcher's working
directory is not readable in this sandbox. */
const http = require('http');
const fs = require('fs');
const path = require('path');
const ROOT = '/Users/Studio/Documents/church-translate/app';
const TYPES = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.json': 'application/json' };
http.createServer((req, res) => {
const rel = decodeURIComponent(req.url.split('?')[0]).replace(/^\/+/, '') || '_preview-langlist.html';
const file = path.join(ROOT, rel);
if (!file.startsWith(ROOT)) { res.writeHead(403).end('no'); return; }
fs.readFile(file, (err, buf) => {
if (err) { res.writeHead(404).end('not found: ' + rel); return; }
res.writeHead(200, { 'Content-Type': TYPES[path.extname(file)] || 'application/octet-stream' });
res.end(buf);
});
}).listen(4873, '127.0.0.1', () => console.log('preview on http://127.0.0.1:4873'));