Environment Variables
Secrets for Cloudflare Pages Functions (API keys, etc.) are set in the Cloudflare dashboard - not in code.
Where to set them
Section titled “Where to set them”Cloudflare Pages -> project -> Settings -> Environment variables
Add variables under Production for the live site. Add under Preview for PR previews.
How to read them in Functions
Section titled “How to read them in Functions”type Env = { CASHFREE_APP_ID: string; CASHFREE_SECRET_KEY: string; CASHFREE_ENV: string;};
type PagesContext = { request: Request; env: Env;};
export const onRequestPost = async ({ request, env }: PagesContext) => { const appId = env.CASHFREE_APP_ID; // ✅ correct};Local development
Section titled “Local development”For local dev with wrangler pages dev, create a .dev.vars file in the project root:
CASHFREE_APP_ID=your_app_id_hereCASHFREE_SECRET_KEY=your_secret_hereCASHFREE_ENV=sandboxNever commit .dev.vars to git. Add it to .gitignore:
.dev.varsVariables for each integration
Section titled “Variables for each integration”Cashfree
Section titled “Cashfree”| Variable | Description |
|---|---|
CASHFREE_APP_ID |
App ID from Cashfree merchant dashboard |
CASHFREE_SECRET_KEY |
Secret key from Cashfree merchant dashboard |
CASHFREE_ENV |
sandbox for testing, production for live |
Other common variables
Section titled “Other common variables”| Variable | Description |
|---|---|
WEB3FORMS_KEY |
Not needed - key is safe to put in HTML |
After setting variables
Section titled “After setting variables”Trigger a new deploy (or push a commit) - Pages Functions pick up the new variables on the next build. Changes to variables do not auto-redeploy.