Cloudflare Pages Setup
Step-by-step guide for deploying a new site.
1. Push to GitHub
Section titled “1. Push to GitHub”Create a new repo on GitHub and push the project:
git initgit add .git commit -m "feat: initial build"git remote add origin https://github.com/<org>/<repo>.gitgit push -u origin main2. Create a Pages project
Section titled “2. Create a Pages project”- Log in to dash.cloudflare.com
- Go to Workers & Pages -> Create application -> Pages -> Connect to Git
- Authorise GitHub if not already done
- Select the repo -> click Begin setup
3. Build settings
Section titled “3. Build settings”| Setting | Value |
|---|---|
| Production branch | main |
| Build command | npm run build |
| Build output directory | dist |
| Root directory | (leave empty) |
Click Save and Deploy.
4. Add custom domains
Section titled “4. Add custom domains”After the first deploy:
- Go to the Pages project -> Custom domains
- Click Set up a custom domain
- Enter
domain.com-> confirm - Repeat for
www.domain.com
Cloudflare auto-creates the CNAME records for both when you add them through the Pages dashboard - no manual DNS editing needed (as long as the domain’s DNS is already on Cloudflare).
5. Set environment variables
Section titled “5. Set environment variables”Go to the Pages project -> Settings -> Environment variables -> Production.
For sites with Cashfree payments:
| Variable | Value |
|---|---|
CASHFREE_APP_ID |
From Cashfree dashboard |
CASHFREE_SECRET_KEY |
From Cashfree dashboard |
CASHFREE_ENV |
production |
Click Save. Trigger a new deploy after setting variables.
6. Verify the deploy
Section titled “6. Verify the deploy”- Visit
https://domain.com- should load - Visit
https://www.domain.com- should redirect tohttps://domain.com - Visit
https://domain.com/robots.txt- should show sitemap URL - Visit
https://domain.com/sitemap-index.xml- should list pages
Auto-deploys
Section titled “Auto-deploys”Every push to main triggers a new build automatically. No manual action needed after the initial setup.
Preview deployments
Section titled “Preview deployments”Every pull request gets a temporary preview URL (<hash>.pages.dev). Useful for reviewing changes before merging.