Something went wrong. Try again.
doll.systems community website
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import { createServer } from 'node:http';import { readFile } from 'node:fs/promises';import { extname, resolve, sep } from 'node:path';
// Instrument built pages locally; neither the harness nor its UI ships to visitors.const root = resolve('dist');const port = Number(process.env.BENCHMARK_PORT || 4322);const mime = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.json': 'application/json', '.svg': 'image/svg+xml', '.png': 'image/png', '.gif': 'image/gif', '.avif': 'image/avif', '.woff2': 'font/woff2', '.xml': 'application/xml', '.txt': 'text/plain',};const harness = await readFile(new URL('./render-benchmark.js', import.meta.url));createServer(async (request, response) => { try { const path = decodeURIComponent(new URL(request.url, `http://127.0.0.1:${port}`).pathname); if (path === '/__render-benchmark.js') { response.writeHead(200, { 'Content-Type': mime['.js'] }).end(harness); return; } if (path === '/__baseline/') { response.writeHead(200, { 'Content-Type': mime['.html'] }).end(`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Browser frame baseline</title><script src="/__render-benchmark.js"></script></head><body style="background:#080808;color:#ddd;font:16px monospace"><h1>Browser frame baseline</h1><p>No site styles, artwork, graph, or animation.</p><a href="/" style="color:#c79fef">Measure the site</a></body></html>`); return; } const file = resolve(root, `.${path.endsWith('/') ? `${path}index.html` : path}`); if (!file.startsWith(root + sep)) { response.writeHead(403).end(); return; } let body = await readFile(file); if (extname(file) === '.html') body = Buffer.from( body.toString().replace('<head>', '<head><script src="/__render-benchmark.js"></script>'), ); response .writeHead(200, { 'Content-Type': mime[extname(file)] || 'application/octet-stream', 'Cache-Control': 'no-store', }) .end(body); } catch { response.writeHead(404).end('Not found'); }}).listen(port, '127.0.0.1', () => console.log(`Rendering benchmark: http://127.0.0.1:${port}/`));