Deploying to Cloudflare Pages

Updated
  • Cloudflare
  • Deployment
Soft warm-grey gradient, a placeholder standing in for a real hero image.

The full walkthrough is in docs/04-cloudflare-pages.md. This post exists mainly to demonstrate a second date in the frontmatter — note the “Updated” line under the title, which only appears because updatedDate differs from pubDate.

The short version

  1. Push the repo to GitHub.
  2. In the Cloudflare dashboard: Workers & Pages → Create → Pages → Connect to Git.
  3. Build command npm run build, output directory dist.
  4. Add any PUBLIC_* variables from your .env to the Pages project settings — they are build-time values, so the build needs them.
  5. Deploy.

Anything under functions/ is picked up automatically as a Pages Function and served at the matching path, which is how /api/contact works without a separate server.

What doesn’t work locally

Pages Functions and bindings (D1, KV, R2) don’t exist under plain astro dev — that’s a static dev server. Use npm run pages:dev to build and serve through Wrangler when you need to exercise them. The contact form is written to tolerate the API being absent, so ordinary astro dev work is unaffected.