Skip to content

Overview

cosmos-digital-services is the public marketing and lead-generation site for cosmosdigitalservices.com. It lives in the monorepo at apps/cosmos/digital-services.

  • An Astro site that builds to mostly static HTML, assets, and client scripts.
  • Cloudflare Workers at the edge for auth/session APIs, protected route enforcement, non-auth /api/* handling, and optional image resizing.
  • A protected admin-style utility at /portal/outgoing-mail for authenticated outgoing mail (worker-backed).
  • Not Astro SSR-first: behavior is static-first; edge workers augment routing and APIs.
  • Not where Cloudflare Access “lives”: Access is configured in Cloudflare; the app and gateway worker consume Access JWTs and cookies.
  1. Astro renders pages, layouts, metadata, and browser scripts from apps/cosmos/digital-services/src/.
  2. src/middleware.ts can rewrite most requests to /maintenance when PUBLIC_MAINTENANCE_MODE === 'true'.
  3. workers/auth-gateway.js handles /api/auth/session, /api/auth/logout, enforces protected prefixes (/portal*, /admin* by default), and delegates other /api/* to shared edge utilities.
  4. workers/image-optimizer.js serves optimized images when the path matches configured routes and query params (see Worker flow).

Shared UI and theming come from workspace packages such as @cosmos/ui-astro, @cosmos/theme, and @cosmos/edge-utils—the app is not fully self-contained.

Authentication is not implemented as Astro server routes for session. The gateway worker validates tokens (Cloudflare Access JWT header or cookie, or Authorization: Bearer) by calling AUTH_WORKER_VERIFY_URL. The layout script calls GET /api/auth/session on load; JSON success: true drives the header switch from Login to Logout and admin nav.

  • apps/cosmos/digital-services/README.md
  • apps/cosmos/digital-services/package.json
  • apps/cosmos/digital-services/src/layouts/Layout.astro
  • apps/cosmos/digital-services/src/middleware.ts
  • apps/cosmos/digital-services/workers/auth-gateway.js