Skip to content

Add Cloudflare Workers support - #3

Merged
njncalub merged 2 commits into
mainfrom
claude/cloudflare-workers-support-4da4ca
Nov 24, 2026
Merged

njncalub merged 2 commits into
mainfrom
claude/cloudflare-workers-support-4da4ca

Conversation

@njncalub

Copy link
Copy Markdown
Contributor

What

The same static dist/ build can now be served from Cloudflare Workers as static assets, alongside the existing GitHub Pages deploy. There's no Worker script and no Astro adapter, so the GitHub Pages build behaves the same as before.

  • wrangler.jsonc: serves dist/ with auto-trailing-slash (same URLs as GitHub Pages) and 404-page handling, so unknown URLs get 404.html with a real 404 status.
  • Real 301s for old URLs: a small build integration in astro.config.mjs writes dist/_redirects from the existing redirects list. GitHub Pages ignores the file and keeps its meta-refresh pages.
  • public/_headers: immutable caching for /_astro/*, plus nosniff and Referrer-Policy.
  • SITE_URL: sets the site URL for canonical links, the sitemap and robots.txt. It defaults to https://indigitousph.github.io. robots.txt is now generated by src/pages/robots.txt.ts, so its sitemap URL follows SITE_URL.
  • Scripts: pnpm preview:cf runs wrangler dev on the built site; pnpm deploy:cf builds and runs wrangler deploy.
  • .github/workflows/deploy-cloudflare.yml: deploys on push to main, daily at 00:05 Manila (so events still expire) and by manual run. It skips itself until the repo is configured (see below).
  • Docs: the Deploy section of AGENTS.md, the README and .env.example.

Why

So the site can be hosted on Cloudflare (custom domain, edge caching, real redirects) without giving up GitHub Pages.

Notes for reviewers

  • pnpm-workspace.yaml is new. pnpm 12 won't run install scripts unless they're approved, and wrangler needs esbuild and workerd to run theirs, so this file approves those two (allowBuilds).
  • Wrangler version: wrangler is pinned to ^4.166.0, because pnpm's minimum-release-age policy rejected the newer 4.167.0.
  • Setup to turn on Cloudflare deploys:
    • the repository variable CLOUDFLARE_ACCOUNT_ID
    • the secret CLOUDFLARE_API_TOKEN ("Edit Cloudflare Workers" template)
    • optionally, the variable CLOUDFLARE_SITE_URL
  • Custom domain: add a routes entry in wrangler.jsonc.

Testing

  • pnpm build: 0 errors and 0 warnings, both with and without SITE_URL.
  • wrangler dev on dist/:
    • pages return 200, and /about redirects to /about/
    • /give, /fil/about and /about/team return 301 to the right targets
    • /nope returns the 404 page with a 404 status
    • /_redirects and /_headers aren't served as files
    • the cache and security headers are present
  • Not yet deployed to a real Cloudflare account.

Serve the static dist/ build from Cloudflare Workers as static assets,
alongside the existing GitHub Pages deploy.

- wrangler.jsonc: assets from dist/, trailing-slash handling, 404 page
- Build writes dist/_redirects so old URLs get real 301s on Workers
- public/_headers: immutable caching for /_astro/*, basic security headers
- SITE_URL sets the site URL for canonical links, sitemap and robots.txt
  (robots.txt is now generated so its sitemap URL follows SITE_URL)
- pnpm preview:cf / deploy:cf scripts; wrangler as a dev dependency
- deploy-cloudflare.yml workflow, off until CLOUDFLARE_ACCOUNT_ID is set
- Docs: AGENTS.md deploy section, README, .env.example
The Worker connected through Cloudflare's Git integration is named
"indigitous", so wrangler.jsonc must use that name. Document the
Workers Builds setup, its SITE_URL build variable, and that it does
not rebuild daily.
@njncalub
njncalub merged commit f888625 into main Nov 24, 2026
2 of 3 checks passed
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