Skip to content

Environment Variables

Secrets for Cloudflare Pages Functions (API keys, etc.) are set in the Cloudflare dashboard - not in code.


Cloudflare Pages -> project -> Settings -> Environment variables

Add variables under Production for the live site. Add under Preview for PR previews.


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
};

For local dev with wrangler pages dev, create a .dev.vars file in the project root:

CASHFREE_APP_ID=your_app_id_here
CASHFREE_SECRET_KEY=your_secret_here
CASHFREE_ENV=sandbox

Never commit .dev.vars to git. Add it to .gitignore:

.dev.vars

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
Variable Description
WEB3FORMS_KEY Not needed - key is safe to put in HTML

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.