Skip to main content
Environment variables live in astro-app/.env for local development. Copy the example file to get started:
For production, variables are set in the Cloudflare Pages dashboard for each project — the .env file is not deployed.
Never commit your .env file to version control. It is listed in .gitignore by default. Server-side secrets (tokens, OAuth credentials) must never appear in public-prefixed variables.

Sanity configuration

These variables connect the Astro app and Sanity Studio to your Sanity project.

PUBLIC_SANITY_STUDIO_PROJECT_ID

Required. Your Sanity project ID.
To find your project ID:
  1. Go to sanity.io/manage.
  2. Select your project.
  3. The project ID appears in the URL and on the project overview page.
This variable used to be PUBLIC_SANITY_PROJECT_ID in older versions of the project. Both names are supported in astro.config.mjs, but prefer the PUBLIC_SANITY_STUDIO_PROJECT_ID form as shown in .env.example.

PUBLIC_SANITY_DATASET

Required. The Sanity dataset to query. Defaults to production.
The project supports multiple datasets for multi-site deployments:

SANITY_API_READ_TOKEN

Required for Visual Editing. A Sanity API token with Viewer permissions, used to fetch draft content in the Presentation tool.
To generate a token:
  1. Go to sanity.io/manage and select your project.
  2. Navigate to Settings → API → Tokens.
  3. Click Add API token, give it a name (e.g., local-visual-editing), and set the role to Viewer.
  4. Copy the token — it is only shown once.
This is a server-side secret. It does not have the PUBLIC_ prefix and is never exposed to the browser. Keep it out of version control.

Multi-site configuration

The platform supports multiple sites from a single codebase. These variables control which site context and theme are active at build time.

PUBLIC_SITE_ID

Identifies the active site. Controls dataset selection, navigation, and theme.

PUBLIC_SITE_THEME

Sets the color theme for the active site. Must be one of red, blue, or green.
If an invalid theme is provided, the build falls back to red and logs a warning in the console.

Visual Editing

PUBLIC_SANITY_VISUAL_EDITING_ENABLED

Enables or disables Sanity’s Visual Editing overlay (stega encoding + Presentation tool).
When true, the Sanity client bypasses the CDN and fetches live draft content. This is automatically enabled on the preview branch in Cloudflare Pages.

PUBLIC_SANITY_LIVE_CONTENT_ENABLED

Enables client-side live content subscriptions via the Live Content API. Allows content updates to appear in the browser without a full page reload.

URLs and routing

PUBLIC_SANITY_STUDIO_URL

The base URL of your Sanity Studio. Used by the Visual Editing stega overlay to generate “Edit in Studio” links.

PUBLIC_SITE_URL

The canonical URL of the deployed site. Used for generating canonical <link> tags and the sitemap.

Analytics and integrations

PUBLIC_GTM_ID

Google Tag Manager container ID. Leave empty to disable tracking.

PUBLIC_TURNSTILE_SITE_KEY

Cloudflare Turnstile site key for bot protection on forms. Obtain from the Cloudflare dashboard under Turnstile.

Server-side secrets

The following secrets are server-side only and must never have the PUBLIC_ prefix. For local development, set them in astro-app/.dev.vars (for Wrangler) or your .env file. For production, use wrangler secret put <NAME> or the Cloudflare Pages dashboard.
For local development, most server-side secrets are not needed. The middleware bypasses authentication when import.meta.env.DEV is true.

Complete .env.example

For reference, here is the full .env.example file from the repository: