Skip to content

feat!: serve the reference from a Cloudflare Worker - #14

Draft
hbrombeer wants to merge 2 commits into
mainfrom
feat/cloudflare-worker
Draft

feat!: serve the reference from a Cloudflare Worker#14
hbrombeer wants to merge 2 commits into
mainfrom
feat/cloudflare-worker

Conversation

@hbrombeer

Copy link
Copy Markdown
Member

Replaces the nginx container image with a Cloudflare Worker that serves the same static Scalar build, and removes the container tooling that is now unused.

Deployed and verified at https://apidocs-demo.grounds.workers.dev/docs/.

What changed

  • worker/index.ts owns routing and reads the build output through the ASSETS binding: / and /docs redirect to /docs/, /docs/healthz returns ok, unknown paths below /docs/ fall back to the application shell, everything outside /docs is 404. Cache classes match the previous nginx configuration (immutable bundles, max-age=300 specs, no-cache shell).
  • worker/index.test.ts covers that contract (9 cases); CI now builds the Worker bundle with wrangler deploy --dry-run where it previously ran the container smoke test.
  • Removed: Dockerfile, .dockerignore, nginx/default.conf, scripts/container-smoke.sh, and the GHCR publish job.
  • The release workflow deploys the Worker from the tagged revision.

Note on the asset server

assets.html_handling must stay "none". With the default (auto-trailing-slash) the asset server answers unknown paths with a 307 to /, which escapes the /docs base path and drops the deep link — reproduced locally before the change.

Follow-ups (not in this PR)

  • Repository secrets CLOUDFLARE_API_TOKEN (Workers Scripts: Edit) and CLOUDFLARE_ACCOUNT_ID must be added before the release workflow can deploy.
  • api.grounds.gg/docs still points at the Kubernetes deployment. Moving it means a Worker custom domain or route and removing the image pin in grounds-pulumi.
  • The Worker is named apidocs-demo; rename before it becomes the production reference.

The reference was published as an nginx container image that grounds-pulumi
had to pin, deploy, and route. Hosting the same static build on a Cloudflare
Worker removes that chain: the build output is uploaded with the Worker and
served from Cloudflare's edge, so a release is a deploy rather than an image
bump in another repository.

worker/index.ts reproduces the routing contract the nginx configuration
provided — base-path redirect, health endpoint, cache classes, application
shell fallback, and 404 outside /docs — and worker/index.test.ts covers it.
The asset server is configured to resolve exact paths only, because its HTML
handling redirects unknown paths to /, which escapes the /docs base path.

BREAKING CHANGE: the container image ghcr.io/groundsgg/api-reference is no
longer built or published. Deployments move to the Cloudflare Worker
apidocs-demo, and the release workflow needs the CLOUDFLARE_API_TOKEN and
CLOUDFLARE_ACCOUNT_ID repository secrets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant