SSR / foldkit-host

What each host part owns

PartWhat it owns
Host.isolateBuild a value once per binding, retrying if initialization fails
Host.templateRead /index.html and its build id from assets once per isolate
Host.routesDispatch assets, check ORIGIN, match routes, then run otherwise
Host.nodeAdapt the same handler to Node's http server with origin checks

Every other concern stays with the package built for it:

  • Page routes and status codes belong to your fallback entry (Site.parse from foldkit-site and SSR.entry's status from foldkit-ssr).
  • Response caching belongs to SSR.entry's cache for pages and serveFetch's cache for Remote reads.
  • Who is asking is resolved per request by foldkit-auth's AuthServer.host; nothing inside Host.isolate may hold a user principal.
  • Durable Objects and media routes are added in your routes map because Workers require Durable Object classes to be exported from your Worker module.
  • Bindings (DB, ASSETS, secrets) are declared in wrangler.toml or your deployment stack before the host runs.

How requests are ordered

A request runs through four stages in fixed order:

  1. Assets (/assets/ from the binding) run first, so an unconfigured Worker still serves its static build.
  2. Origin check verifies the ORIGIN environment variable is set; if missing or empty, it returns 500 naming the variable. Configured explicitly rather than read from the request header so a Worker reachable on a second host (like workers.dev) trusts only its configured origin.
  3. Routes match in order ('/auth/' by prefix, '/remote' by exact path).
  4. Fallback (otherwise) renders the page.