Skip to main content
The Astro frontend deploys to Cloudflare Pages via native git integration. Every push triggers a build; the branch name determines which environment is targeted.

Deployment environments

Production

Branch: mainStatic output (output: "static"), Visual Editing OFF. All public pages are pre-rendered to static HTML at build time and served from Cloudflare’s edge CDN with zero Worker invocations.

Preview / Staging

Branch: any branch other than mainSSR enabled via @astrojs/cloudflare adapter, Visual Editing ON with draft content from Sanity. Each branch gets a unique preview URL: branch-name.ywcc-capstone.pages.dev.
The preview branch acts as the staging environment. It deploys to preview.ywcc-capstone.pages.dev with SSR and Visual Editing enabled so editors can review draft content before it ships.

How it works

Content rebuilds use a Cloudflare deploy hook — the simplest possible pipeline with no GitHub Actions in the loop.

Build configuration

Root directory must be /, not astro-app/. The build command uses npm workspaces which requires the monorepo root package.json to resolve all workspace packages.

Create the Pages project

1

Connect the repository

Go to dash.cloudflare.comWorkers & PagesCreatePagesConnect to Git → select the astro-shadcn-sanity repo.
2

Configure the build

Set the project name to ywcc-capstone, build command, and output directory as shown in the table above.
3

Set environment variables

Add all required environment variables (see section below) before saving. Variables set here are available at build time and runtime.
4

Deploy

Click Save and Deploy. The first build will run immediately. Subsequent builds trigger automatically on every git push.

Environment variables

Set these in CF Pages → ywcc-capstone → Settings → Environment variables for both Production and Preview environments.

Public variables (plaintext)

Secrets (encrypted)

GitHub Actions secrets (CI only)

Multi-project deployment

The same Astro codebase deploys as three independent CF Pages projects, each with different environment variables: All three share the same repo, build command, and output directory. Only the environment variables differ. No code branching per site — PUBLIC_SITE_ID controls GROQ filtering and PUBLIC_SITE_THEME controls the CSS theme.

Build caching

Cloudflare Pages caches build outputs across deployments. The SKIP_DEPENDENCY_INSTALL=true environment variable tells the CF Pages v3 build image to skip the automatic npm clean-install step (which would delete and reinstall all packages from scratch every build). What gets cached:
Build cache expires after 7 days without a build. If node_modules is cold and SKIP_DEPENDENCY_INSTALL=true, the build may fail. Temporarily remove the variable to force a full install and repopulate the cache, then re-add it.

Build watch paths

Configured per project to avoid unnecessary rebuilds:
  • Include: astro-app/*, package-lock.json
  • Exclude: studio/*, _templates/*, docs/*, tests/*, .github/*, CHANGELOG.md, README.md
Schema changes in studio/ don’t trigger builds directly. Running npm run typegen updates astro-app/src/sanity.types.ts, which is in the watch path.

Set up the deploy hook

1

Create the hook

CF Pages → ywcc-capstoneSettingsBuilds & deploymentsDeploy hooksAdd deploy hook.Name: Sanity Content Publish, Branch: mainSave. Copy the generated URL — treat it as a secret.
2

Configure the Sanity webhook

sanity.io/manage → your project → APIWebhooks → create or edit the webhook:
3

Verify

Publish a content change in Sanity Studio. Check sanity.io/manage → Webhooks → Attempts tab for a 200 OK response, then check CF Pages dashboard for a new production build.

Security headers

astro-app/public/_headers applies these response headers on all routes via Cloudflare Pages CDN:
These headers are only active on deployed Cloudflare Pages. They do not apply in local wrangler pages dev or astro dev.

Local Wrangler preview

To preview the production build locally using Miniflare:
Runs on http://localhost:8788.

Troubleshooting