Deploying to Cloudflare Pages
Cloudflare Pages is one of the best platforms for hosting static sites. Here’s why and how.
Why Cloudflare Pages?
- Edge network – Your site is served from 300+ locations worldwide
- Generous free tier – Unlimited requests, 500 builds/month
- Automatic HTTPS – SSL certificates handled automatically
- Git integration – Push to deploy, preview deployments on every PR
- Custom domains – Free, including www redirects
Setup Steps
1. Connect Your Repository
- Go to dash.cloudflare.com
- Navigate to Pages → Create a project
- Connect your GitHub/GitLab repository
2. Configure Build Settings
For an Astro project:
| Setting | Value |
|---|---|
| Framework preset | Astro |
| Build command | pnpm build |
| Build output directory | dist |
| Node.js version | 20.x |
3. Add Environment Variables
If your build requires environment variables, add them in the Pages dashboard under Settings → Environment variables.
4. Custom Domain
- Go to Custom domains in your project
- Enter your domain name
- Follow the DNS setup instructions
Since my domain is already managed by Cloudflare, the DNS records are added automatically.
Automatic Deployments
Every push to main triggers a production deployment. Every PR gets a unique preview URL – perfect for reviewing changes before merging.
That’s it! The whole setup takes about 5 minutes.