Something went wrong. Try again.
🌿 Collaborative wiki on ATProto forked from juprodh.me/lichen.wiki
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748interface HtmlResponseOptions { status?: number; edgeCacheSeconds?: number;}
// Strict CSP — no 'unsafe-inline' for scripts. All client behaviors live in// /public/*.js. Inline <style> still allowed because Tailwind tokens are// emitted into a per-theme <style> block in the layout.//// External script sources covered: htmx, csrf.js, ui.js, editor, viz (all// 'self'); D3 (cdn.jsdelivr.net); GoatCounter (stats.lichen.wiki);// Cloudflare insights (static.cloudflareinsights.com).const CSP_DIRECTIVES = [ "default-src 'self'", "script-src 'self' https://stats.lichen.wiki https://static.cloudflareinsights.com https://cdn.jsdelivr.net", "style-src 'self' 'unsafe-inline'", "img-src 'self' data: https://cdn.bsky.app", "font-src 'self' data:", "connect-src 'self' https://stats.lichen.wiki https://cloudflareinsights.com", "frame-src https://www.youtube-nocookie.com", "frame-ancestors 'none'", "base-uri 'self'", "form-action 'self'", "object-src 'none'",].join("; ");
export function htmlResponse( body: string, statusOrOptions: number | HtmlResponseOptions = 200,): Response { const opts: HtmlResponseOptions = typeof statusOrOptions === "number" ? { status: statusOrOptions } : statusOrOptions; const headers: Record<string, string> = { "Content-Type": "text/html", "Content-Security-Policy": CSP_DIRECTIVES, "X-Content-Type-Options": "nosniff", "Referrer-Policy": "strict-origin-when-cross-origin", }; if (opts.edgeCacheSeconds && opts.edgeCacheSeconds > 0) { headers["Cache-Control"] = `public, s-maxage=${opts.edgeCacheSeconds}, stale-while-revalidate=${opts.edgeCacheSeconds * 5}`; headers["Vary"] = "Cookie, Accept-Language"; } return new Response(body, { status: opts.status ?? 200, headers });}