Repository navigation
Add Cloudflare Workers support - #3
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: servesdist/withauto-trailing-slash(same URLs as GitHub Pages) and404-pagehandling, so unknown URLs get404.htmlwith a real 404 status.astro.config.mjswritesdist/_redirectsfrom the existingredirectslist. GitHub Pages ignores the file and keeps its meta-refresh pages.public/_headers:immutablecaching for/_astro/*, plusnosniffandReferrer-Policy.SITE_URL: sets the site URL for canonical links, the sitemap androbots.txt. It defaults tohttps://indigitousph.github.io.robots.txtis now generated bysrc/pages/robots.txt.ts, so its sitemap URL followsSITE_URL.pnpm preview:cfrunswrangler devon the built site;pnpm deploy:cfbuilds and runswrangler deploy..github/workflows/deploy-cloudflare.yml: deploys on push tomain, daily at 00:05 Manila (so events still expire) and by manual run. It skips itself until the repo is configured (see below)..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.yamlis new. pnpm 12 won't run install scripts unless they're approved, andwranglerneedsesbuildandworkerdto run theirs, so this file approves those two (allowBuilds).wrangleris pinned to^4.166.0, because pnpm's minimum-release-age policy rejected the newer 4.167.0.CLOUDFLARE_ACCOUNT_IDCLOUDFLARE_API_TOKEN("Edit Cloudflare Workers" template)CLOUDFLARE_SITE_URLroutesentry inwrangler.jsonc.Testing
pnpm build: 0 errors and 0 warnings, both with and withoutSITE_URL.wrangler devondist/:/aboutredirects to/about//give,/fil/aboutand/about/teamreturn 301 to the right targets/nopereturns the 404 page with a 404 status/_redirectsand/_headersaren't served as files