Web Worker and hosts
cemco-web (workers/web) is one Worker with static assets in front of three sites.
Build and assemble
Section titled “Build and assemble”apps/app (vite build) -> workers/web/public/appapps/www (astro build) -> workers/web/public/wwwapps/docs (astro build) -> workers/web/public/docsbun run --filter @cemco/web assemblebun run build at the root does all four. The assemble step checks that each site was built, hashes every inline
<script> into public/csp-hashes.json (outside the site folders, so no public URL reaches it), and writes
public/.assetsignore so source maps are not uploaded (set KEEP_SOURCEMAPS=1 to keep them).
Routing
Section titled “Routing”| Request | Site |
|---|---|
app.cemco.app |
app (SPA: unknown paths without a file extension get the app shell) |
www.cemco.app |
www |
docs.cemco.app |
docs |
cemco.app |
301 to https://www.cemco.app with the same path |
localhost:8787, www.localhost:8787, docs.localhost:8787 |
app, www, docs (local development) |
The asset server’s own redirects (trailing slashes) are rewritten so the internal /app, /www or /docs folder
never shows. Unknown pages on www and docs get that site’s 404 page with status 404.
Preview on one host
Section titled “Preview on one host”A preview deployment lives on a single cemco-web.<account>.workers.dev host. There, outside production only:
/www,/docsor/app(with or without a path after it) switches to that site and redirects to the path, for example/docs/guide/orders/→/guide/orders/on the docs site;?site=docsdoes the same without a redirect;- the choice is kept in a
cemco_sitecookie; with no choice yet, the landing page is shown.
The redirect always stays on the host: leading slashes and backslashes after the prefix collapse to one, so
/docs//evil.example goes to /evil.example on the docs site, never to another host. A site parameter is dropped
from the redirect because the prefix already chose.
Because the three sites share one origin there, the app’s root-scoped service worker would answer every later page
load with the app shell. On a single preview host the Worker therefore serves a self-unregistering /sw.js (it drops
the app’s caches and reloads any page an earlier worker was serving) and a no-op /registerSW.js. The app runs
without offline support on a preview host. Every response there is no-store, because the same URL can return a
different site depending on the cookie.
Production ignores all of this. Outside production the Worker also rewrites the production links baked into the pages
(https://app.cemco.app/...) to the current host.
Proxies
Section titled “Proxies”On the app host (and on a single preview host) the Worker proxies, keeping the browser same-origin:
| Path | To | Upstream path |
|---|---|---|
/api/* |
API (cemco-api) |
without /api (/api/v1/me → /v1/me) |
/auth/* |
AUTH (cemco-auth) |
unchanged |
/agents/* |
AGENTS (cemco-agents) |
unchanged, WebSocket upgrades included |
Method, body, query and cookies are passed through. The Worker sets x-forwarded-host and x-forwarded-proto
itself (any value from the browser is dropped), and x-forwarded-prefix: /api on API calls, which cemco-api uses for
its own URLs (such as the OpenAPI server URL) when API_URL is not set. Upstream responses are returned untouched; www and docs never proxy.
Headers
Section titled “Headers”Every static response gets X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin,
Cross-Origin-Opener-Policy: same-origin, a Permissions-Policy (camera and location allowed only on the app, for
nameplate photos and the map), and HSTS (max-age=31536000; includeSubDomains) on any HTTPS host that is not localhost.
HTML also gets X-Frame-Options: DENY and a Content-Security-Policy:
default-src 'self',object-src 'none',base-uri 'self',frame-ancestors 'none';script-src 'self'plus the build’s inline-script hashes, never'unsafe-inline'; docs also allows'wasm-unsafe-eval'for the Pagefind search;- the app adds its same-origin WebSocket to
connect-src, Google profile images toimg-src, Google toform-action, andframe-src 'self' blob:for document previews. Signed document links point atcemco-api’s own host when itsAPI_URLis set (https://api.cemco.appin production), so the app also allows that origin, from theAPI_ORIGINvariable ofcemco-web, inframe-src,img-srcandconnect-src.
The app and every non-production response also get X-Robots-Tag: noindex, nofollow.
Caching
Section titled “Caching”| What | Cache-Control |
|---|---|
Hashed assets: /assets/* (app), /_astro/* (www, docs) |
public, max-age=31536000, immutable |
HTML, sw.js, registerSW.js, the web manifest, Pagefind, sitemaps |
no-cache (revalidate every time) |
| Other files (icons) | public, max-age=3600 |
| Errors (404) | no-store |
| Anything on a single preview host | no-store |
robots.txt and sitemaps
Section titled “robots.txt and sitemaps”/robots.txt is answered by the Worker: www and docs allow indexing in production and point at their
/sitemap-index.xml (generated by Astro); the app and every preview disallow everything.