0011. Serving the app: Workers Static Assets and a strict CSP
- Status: Accepted
- Date: 2026-11-23
Context
One Worker serves both the API and the front end (ADR 0002). Local runs and end-to-end tests should exercise exactly what production serves, and the security headers should be proven, not assumed.
Decision
- Workers Static Assets.
apps/webbuilds with Vite intodist/;apps/worker/wrangler.jsoncpointsassets.directoryat it withrun_worker_first: ["/api/*"]andnot_found_handling: "single-page-application". Static files never run Worker code; unknown non-API paths getindex.html; unknown/api/*paths are JSON 404s from the Worker. Local and end-to-end runs usewrangler dev. - Security headers. Static files:
apps/web/public/_headerswith a strict Content-Security-Policy (default-src 'self', no inline script or style,frame-ancestors 'none',object-src 'none'), plusnosniff,Referrer-Policy: no-referrer, a closedPermissions-PolicyandCross-Origin-Opener-Policy. API: Hono'ssecureHeaderswithdefault-src 'none'. Both also sendStrict-Transport-Security(two years,includeSubDomains) and deny framing (X-Frame-Options: DENY); every/api/*answer, errors and 404s included, isCache-Control: no-store. - Proven in CI. The required
appjob runs the Worker underwrangler devand fails on a missing CSP header, any CSP violation in the console, a broken SPA fallback, the shell not reaching the API, and any accessibility failure (the shared checks inscripts/a11y-check.mjs). - One Preact.
apps/web/vite.config.tsdedupespreact, because the docs workspace hoists Preact 10 and@preact/signalswould otherwise bind to it.
Consequences
- No inline scripts or styles, ever: new code that needs them must change the policy in an ADR first.
- The Cloudflare Vite plugin (Worker inside
vite dev) isn't used; local development is two processes (vite build --watch+wrangler dev).