Deploy to Cloudflare Pages
What Is Cloudflare Pages?
Section titled “What Is Cloudflare Pages?”Cloudflare Pages is a static site hosting platform with a global CDN, free SSL, and automatic deployments from Git. It is the recommended hosting option for Astro Docus because:
- Free tier includes unlimited bandwidth and 500 builds per month
- Automatic deploys on every Git push
- Preview deployments for every pull request
- Custom domains supported on the free plan
- No credit card required to get started
This guide covers two methods:
- GitHub Integration (recommended) — Cloudflare builds and deploys automatically
- Direct Upload with Wrangler — deploy from your local machine without GitHub
Prerequisites
Section titled “Prerequisites”Before starting, you need:
- A Cloudflare account (free)
- Your Astro Docus project pushed to GitHub (see the previous guide)
- A terminal open in your project folder
Method 1 — Deploy via GitHub Integration
Section titled “Method 1 — Deploy via GitHub Integration”This is the recommended method. Once set up, every push to your main branch triggers an automatic build and deploy.
Step 1 — Sign Up or Log In to Cloudflare
Section titled “Step 1 — Sign Up or Log In to Cloudflare”- Go to: https://dash.cloudflare.com/sign-up
- Enter your email address and a password
- Click Sign up
- Verify your email by clicking the link Cloudflare sends you
If you already have an account, log in at: https://dash.cloudflare.com/login
Step 2 — Navigate to Pages
Section titled “Step 2 — Navigate to Pages”- After logging in, look at the left sidebar
- Click Workers & Pages
- You are now on the Workers & Pages overview page
Step 3 — Create a New Pages Project
Section titled “Step 3 — Create a New Pages Project”- Click the Create application button
- Select the Pages tab
- Click Connect to Git
Step 4 — Connect Your GitHub Repository
Section titled “Step 4 — Connect Your GitHub Repository”- Cloudflare prompts you to sign in with GitHub
- Click Authorize Cloudflare Pages on the GitHub authorization page
- You can choose to grant access to:
- All repositories (easier, but broader access)
- Only select repositories (recommended for security)
- Select your Astro Docus repository from the list
- Click Install & Authorize
Step 5 — Select the Repository
Section titled “Step 5 — Select the Repository”- Cloudflare shows a list of your GitHub repositories
- Click on your Astro Docus repository
- Click Begin setup
Step 6 — Configure Build Settings
Section titled “Step 6 — Configure Build Settings”This is the most important step. Enter these exact values:
| Configuration option | Value |
|---|---|
| Project name | astrodocus (or any name — becomes your *.pages.dev subdomain) |
| Production branch | main |
| Framework preset | Astro |
| Build command | npm run build |
| Build output directory | dist |
These settings match the official Astro deployment guide .
Note: The
Framework presetdropdown may auto-fill the build command and output directory. Verify they match the values above.
Step 7 — Deploy
Section titled “Step 7 — Deploy”- Click Save and Deploy
- Cloudflare starts building your site
- You see a build log — this shows each step (installing dependencies, building, deploying)
- First build takes 1–3 minutes
- When complete, you see a success message and your live URL
Step 8 — Your Live Site
Section titled “Step 8 — Your Live Site”After deployment, you receive a unique URL:
https://astrodocus.pages.dev(The exact subdomain depends on your project name.)
Open this URL in your browser. Your Astro Docus site is now live.
Method 2 — Direct Upload with Wrangler
Section titled “Method 2 — Direct Upload with Wrangler”Use this method if you do not want to connect GitHub. You build locally and upload the dist/ folder.
Step 1 — Install Wrangler
Section titled “Step 1 — Install Wrangler”Wrangler is Cloudflare’s command-line tool.
npm install -g wranglerVerify installation:
wrangler --versionStep 2 — Log In to Cloudflare
Section titled “Step 2 — Log In to Cloudflare”wrangler loginThis opens your browser. Log in to Cloudflare and authorize Wrangler.
Step 3 — Build Your Site Locally
Section titled “Step 3 — Build Your Site Locally”npm run buildThis generates the dist/ folder with your static site.
Step 4 — Deploy to Cloudflare Pages
Section titled “Step 4 — Deploy to Cloudflare Pages”npx wrangler pages deploy distWrangler uploads the contents of dist/ to Cloudflare Pages .
Step 5 — First-Time Setup
Section titled “Step 5 — First-Time Setup”On first deploy, Wrangler asks:
- Project name: enter a name (e.g.,
astrodocus) - Production branch: enter
main
After that, the site is live at https://your-project.pages.dev.
Deploying Updates Later
Section titled “Deploying Updates Later”Every time you want to update the live site:
npm run buildnpx wrangler pages deploy distAdding a Custom Domain
Section titled “Adding a Custom Domain”A *.pages.dev subdomain works, but a custom domain looks more professional.
Step 1 — Go to Your Project
Section titled “Step 1 — Go to Your Project”- In the Cloudflare dashboard, go to Workers & Pages
- Click your Pages project
Step 2 — Add Custom Domain
Section titled “Step 2 — Add Custom Domain”- Click the Custom domains tab
- Click Set up a custom domain
- Enter your domain (e.g.,
docs.yourdomain.com) - Click Continue
Step 3 — Configure DNS
Section titled “Step 3 — Configure DNS”If your domain uses Cloudflare nameservers:
- Cloudflare adds the DNS record automatically
- Wait 1–2 minutes for propagation
If your domain is registered elsewhere:
- Cloudflare shows a CNAME record to add
- Go to your domain registrar (Namecheap, GoDaddy, etc.)
- Add a CNAME record pointing to your
*.pages.devURL - Example:
docs→astrodocus.pages.dev
Step 4 — Verify
Section titled “Step 4 — Verify”After DNS propagates (5 minutes to 24 hours), your custom domain works with HTTPS automatically.
How Automatic Deployments Work
Section titled “How Automatic Deployments Work”Once connected to GitHub, Cloudflare Pages watches your repository:
| Action | Result |
|---|---|
Push to main | Production deploy |
| Push to another branch | Preview deploy (unique URL) |
| Open a pull request | Preview deploy with PR comment |
This means you never manually deploy again. Just git push, and Cloudflare handles the rest.
Understanding the Build Process
Section titled “Understanding the Build Process”When Cloudflare builds your Astro Docus site:
- Clones your repository
- Installs dependencies (
npm install) - Runs
npm run build - Reads the
dist/folder - Deploys it to Cloudflare’s global network
The build log shows every step. If something fails, the log tells you exactly where.
Troubleshooting
Section titled “Troubleshooting”| Problem | Likely Cause | Fix |
|---|---|---|
404 errors on *.pages.dev | Missing index.html at root | Check that dist/index.html exists |
| Build fails | Wrong Node version | Set NODE_VERSION environment variable |
| Build succeeds but site is blank | Wrong output directory | Verify dist is set correctly |
| Wrangler authentication fails | Token lacks Pages permission | Create API token with Cloudflare Pages: Edit scope |
| Custom domain not working | DNS not propagated | Wait longer, or check CNAME record |
| Slow build times | No cache | Cloudflare caches node_modules/.astro automatically for Astro |
Environment Variables (Optional)
Section titled “Environment Variables (Optional)”If your project needs environment variables (API keys, analytics tokens), set them in:
Cloudflare Dashboard → Your Pages project → Settings → Environment variables
Common variables for Astro Docus:
| Variable | Value | Purpose |
|---|---|---|
NODE_VERSION | 20 | Ensures correct Node.js version |
CF_ANALYTICS_TOKEN | your token | Cloudflare Web Analytics |
Set these before your first deploy if needed.
Quick Recap
Section titled “Quick Recap”Method 1 — GitHub Integration (recommended):1. Sign up at cloudflare.com2. Workers & Pages → Create application → Pages3. Connect to Git → Authorize GitHub4. Select your Astro Docus repository5. Build settings: - Build command: npm run build - Output directory: dist6. Save and Deploy7. Your site is live at *.pages.dev
Method 2 — Wrangler Direct Upload:1. npm install -g wrangler2. wrangler login3. npm run build4. npx wrangler pages deploy dist5. Live at *.pages.dev
Custom Domain:- Dashboard → Your project → Custom domains- Add domain → Configure DNS- HTTPS automaticCloudflare Pages is free, fast, and automatic. Once connected to GitHub, every git push deploys your site globally in under two minutes.
👉 Next: docs/deploy-hosting/vercel.md — deploy to Vercel.