Files
zeekayandHanzo Dev 9e789e513d the review flag gates what the policies claim
legal.ts exported REVIEWED = false and nothing read it, so the drafts published as
though they were in force. It renders the notice now, on the index and on every
policy, and disappears when counsel flips the flag.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-10 12:03:27 -07:00

54 lines
1.8 KiB
JavaScript

/*
Serves the export the way the Worker's asset handler does, which
`python3 -m http.server` does not: `next export` writes `console.html`, not
`console/index.html`, so a bare `/console` 404s under a plain file server and the
suite could only ever reach `/`. Eight of nine pages were untestable.
Three rules, in the order the Worker applies them: an exact file, then
`<path>.html`, then `<path>/index.html`. Anything else is the 404 page, with the
404 status — a soft 404 that answers 200 is how a broken link ships.
*/
import { createServer } from 'node:http'
import { readFile } from 'node:fs/promises'
import { extname, join, normalize } from 'node:path'
const ROOT = new URL('../out/', import.meta.url).pathname
const PORT = Number(process.env.PORT ?? 3000)
const TYPES = {
'.html': 'text/html; charset=utf-8',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.svg': 'image/svg+xml',
'.woff2': 'font/woff2',
'.ttf': 'font/ttf',
'.txt': 'text/plain; charset=utf-8',
}
async function read(p) {
try {
return await readFile(p)
} catch {
return null
}
}
createServer(async (req, res) => {
const path = normalize(decodeURIComponent(new URL(req.url, 'http://x').pathname)).replace(/^(\.\.[/\\])+/, '')
const base = join(ROOT, path)
const candidates = extname(path)
? [base]
: [base, `${base.replace(/\/$/, '')}.html`, join(base, 'index.html')]
for (const c of candidates) {
const body = await read(c)
if (body) {
res.writeHead(200, { 'Content-Type': TYPES[extname(c)] ?? 'application/octet-stream' })
return res.end(body)
}
}
res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' })
res.end((await read(join(ROOT, '404.html'))) ?? 'Not found')
}).listen(PORT)