Hosted static edge
This optional Worker serves public frontend files from explicitly mapped HTTPS Pages origins. The browser-facing custom domain belongs to the Warmbly zone and uses that zone's certificate and cipher configuration. Pages remains the release artifact store, so existing release uploads continue to update the upstream. Self-hosted deployments do not use this Worker.
PAGES_ORIGINS is a JSON object mapping each exact public hostname to its Pages
origin, for example {"stage.warmbly.com":"https://example.pages.dev"}. It is
operator configuration, never read from the request. The checked-in configuration
has an empty map and no domains or routes. Deploying it alone serves no website.
Only GET, HEAD and OPTIONS reach the static origin. Application authorization and cookies are removed before forwarding. API, forms and realtime traffic keep their existing hosts and paths. Responses retain the Pages security headers, cache policy, assets and status. Redirects back to the selected Pages origin use the visitor's hostname. No request URL, token or body is logged by this Worker.
Deployment and rollback
- Save current DNS, Pages custom-domain associations, certificate settings and production deployment identifiers privately. Identify the account that owns the zone, its existing Workers plan, and any usage charges before deployment.
- Deploy the reviewed module with a private configuration mapping only a staging hostname to one existing Pages production origin. Attach that hostname as a Worker custom domain. Keep all existing production domains on Pages.
- Independently verify certificate trust, the allowed TLS 1.2 AEAD suites, TLS 1.3 and refusal of CBC. Verify the root page, nested SPA routes, JS/CSS assets, redirects, 404 behavior and response security headers against the upstream.
- Prepare the exact production map from authenticated Pages account metadata. Before each cutover, preserve that hostname's DNS and Pages association. Move one hostname at a time to the Worker custom domain and repeat the checks. Keep the Pages projects and deployment history intact.
- If a check fails, restore that hostname's saved Pages association and DNS, then verify it serves the previous content. Do not proceed to another hostname.
For normal releases use the stable production Pages origin. An immutable deployment URL can pin a staging or rollback comparison. The Worker map is a separate reviewed configuration; no release workflow changes it automatically.
Validate with node --test deploy/cloudflare/static-edge.test.mjs and
pnpm dlx wrangler@4.45.0 deploy --dry-run --config deploy/cloudflare/wrangler.jsonc.
Cloudflare custom-domain and certificate API responses are configuration evidence;
independent TLS handshakes are required to establish the effective policy.
Portal
The portal service runs here as a Worker. Its source is portal/worker/ and its
page app is portal/, shared with the self-hosted deployment; only
portal/wrangler.jsonc is Cloudflare's. It answers two kinds of host on the
Cloudflare for SaaS zone PORTAL_DOMAIN is on (CLOUDFLARE_SAAS_PORTAL_ZONE_ID
on the backend):
PORTAL_DOMAINitself, the shared portal address. Every connect link and report of a workspace without an agency portal domain is built on it, for any workspace, agency or not. It serves the client pages below and nothing else: every other path answers the "nothing at this address" page, so the shared address never looks like a sign-in page. No host lookup is made for it.- every agency portal domain, which customers
CNAMEtoPORTAL_DOMAINand Cloudflare issues a certificate for. For each request the Worker asks the backend whether the host is a verified portal domain (GET /api/v1/internal/portals/:host) and keeps only that verdict for a minute, in the isolate and the Worker cache. A host that is not one, including the configured origins themselves, gets a plain404. A lookup that fails answers503and is not cached.
On both:
/connect/<token>and/r/<token>(also with?embed=1) are the client connect page and the shared report: the shell of the page build with a render token stamped in, sent withContent-Security-Policy: frame-ancestors *,X-Robots-Tag: noindex, nofollow,Referrer-Policy: no-referrerandCache-Control: no-store. A report is resolved first, so an unknown or revoked link gets the "no longer shared" page/api/connect/<token>(lookup,/oauth,/oauth/result,/smtp-imap) and/api/reports/<token>are the JSON routes those pages call. Each needs the page's render token, refuses a repeated query parameter or render token, and calls the backend's internalconnect-linksandreportsroutes with the visitor's host, so a portal domain only ever resolves its own agency's clients' links and the shared address resolves any/embed.jsis the embed loader (portal/public/embed.js) and/_portal/assets/the page build's hashed files/f/,/forms.jsand every other/api/path answer404: forms are served by the forms service only- on an agency portal domain, every other GET or HEAD goes to
DASHBOARD_ORIGIN, the dashboard's Pages build, whose_redirectskeep the app's routes onindex.html. Other methods answer405
Per-visitor budgets use Cloudflare rate-limiting bindings, keyed on
CF-Connecting-IP and set in portal/wrangler.jsonc: link lookups 30, sign-in
starts and server-details submits 10, sign-in result polls 60 and report reads
(page and JSON together) 60, each per minute. They count per Cloudflare location
and are approximate; the backend also limits attempts per link. Without the
bindings (workerd on a self-host) the same budgets are counted in the process.
Report answers are kept in the isolate's memory for a minute (half a minute for
a missing link), so a revoke takes effect within it.
The Worker reaches the backend at API_ORIGIN with PORTAL_EDGE_TOKEN, a
Worker secret matching the backend's PORTAL_EDGE_TOKEN. That token opens only
the portal lookup, connect-link and report routes, and nothing else opens them,
so the Worker holds neither INTERNAL_API_TOKEN nor NODE_BROKER_TOKEN.
Cookies and authorization never leave the Worker. Dashboard responses keep
their security headers except Strict-Transport-Security, which is never sent
for a customer's domain. No request URL, token or body is logged.
The checked-in portal/wrangler.jsonc sets no origins, routes or domains.
Deployed as is, it answers 404 to everything. It also leaves FALLBACK_ORIGIN
unset, the self-host image's pass-through for hosts that are not portal domains
(deploy/docker/portal.Dockerfile), so here every other host answers 404. An invalid configuration, a
missing page build or an invalid rate-limit binding answers 503. The entry
module, portal/worker/index.mjs, exports only its handler, because the
runtime starts every export of the main module as an entrypoint.
Building and deploying
The page build is not checked in. Build it, then deploy:
pnpm --dir portal install --frozen-lockfile
pnpm --dir portal build
pnpm dlx wrangler@4.45.0 deploy --config deploy/cloudflare/portal/wrangler.jsonc
pnpm build writes portal/dist/_portal/, the Worker's ASSETS directory.
Rebuild and redeploy whenever a release changes portal/. Like the static edge,
no workflow deploys this Worker; a deploy is a reviewed manual step.
Setting it up on Warmbly Cloud
- Enable Cloudflare for SaaS on the zone
PORTAL_DOMAINlives on. Create the fallback origin as a proxied record (anAAAAto100::is enough, because the Worker answers and nothing is fetched from it) and set it as the zone's fallback origin. CreatePORTAL_DOMAINitself as a proxiedCNAMEto the fallback origin. - Generate a token (
openssl rand -hex 32). Add it asPORTAL_EDGE_TOKENto the backend's secret, add the name to the backend'ssecret_keys, apply the runtime stack and roll the backend. Until the Worker uses it nothing changes. - Build and deploy this Worker with a private configuration:
API_ORIGIN(the public API, such ashttps://api.warmbly.com),PORTAL_DOMAIN(portal.warmbly.com) andDASHBOARD_ORIGIN(the dashboard's production Pages origin). Set the token withwrangler secret put PORTAL_EDGE_TOKEN --config deploy/cloudflare/portal/wrangler.jsonc. Give each rate-limit binding anamespace_idnot used by another Worker on the account. - Route requests to it: a Worker route
portal.warmbly.com/*for the shared address, a route*/*on the zone for custom hostnames, plus routes with no Worker for the zone's other names (warmbly.com/*,*.warmbly.com/*) so they keep their current handling; the more specificportal.warmbly.com/*wins over the last. Confirm that each existing hostname on the zone still answers as before. - Set
PORTAL_DOMAIN,CLOUDFLARE_SAAS_PORTAL_ZONE_IDandCLOUDFLARE_SAAS_PORTAL_API_TOKENon the backend and roll it. Connect links and reports are built on the portal address from then on, and verified portal domains are registered on the zone within two minutes. - Verify on the shared address and on one test portal domain: the certificate,
a connect link (also framed through
/embed.js), a report, a404for/f/<id>, the dashboard on the portal domain and the "nothing at this address" page at the shared address's root. To roll back, remove the Worker routes and unsetPORTAL_DOMAINon the backend, which stops new links being built; registered hostnames stay and serve nothing until the routes return.
To rotate the token, move the current value into the backend's
PORTAL_EDGE_PREVIOUS_TOKENS with a PORTAL_EDGE_PREVIOUS_UNTIL cutoff, set the
new value as PORTAL_EDGE_TOKEN and roll the backend, put the new value in the
Worker, then let the cutoff pass.
Validate with pnpm --dir portal test and, after pnpm --dir portal build,
pnpm dlx wrangler@4.45.0 deploy --dry-run --config deploy/cloudflare/portal/wrangler.jsonc.
Portal CI runs both.