Skip to content

Deploy to 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:

  1. GitHub Integration (recommended) — Cloudflare builds and deploys automatically
  2. Direct Upload with Wrangler — deploy from your local machine without GitHub

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”
  1. Go to: https://dash.cloudflare.com/sign-up
  2. Enter your email address and a password
  3. Click Sign up
  4. Verify your email by clicking the link Cloudflare sends you

If you already have an account, log in at: https://dash.cloudflare.com/login

  1. After logging in, look at the left sidebar
  2. Click Workers & Pages
  3. You are now on the Workers & Pages overview page
  1. Click the Create application button
  2. Select the Pages tab
  3. Click Connect to Git
  1. Cloudflare prompts you to sign in with GitHub
  2. Click Authorize Cloudflare Pages on the GitHub authorization page
  3. You can choose to grant access to:
    • All repositories (easier, but broader access)
    • Only select repositories (recommended for security)
  4. Select your Astro Docus repository from the list
  5. Click Install & Authorize
  1. Cloudflare shows a list of your GitHub repositories
  2. Click on your Astro Docus repository
  3. Click Begin setup

This is the most important step. Enter these exact values:

Configuration optionValue
Project nameastrodocus (or any name — becomes your *.pages.dev subdomain)
Production branchmain
Framework presetAstro
Build commandnpm run build
Build output directorydist

These settings match the official Astro deployment guide .

Note: The Framework preset dropdown may auto-fill the build command and output directory. Verify they match the values above.

  1. Click Save and Deploy
  2. Cloudflare starts building your site
  3. You see a build log — this shows each step (installing dependencies, building, deploying)
  4. First build takes 1–3 minutes
  5. When complete, you see a success message and your live URL

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.


Use this method if you do not want to connect GitHub. You build locally and upload the dist/ folder.

Wrangler is Cloudflare’s command-line tool.

Terminal window
npm install -g wrangler

Verify installation:

Terminal window
wrangler --version
Terminal window
wrangler login

This opens your browser. Log in to Cloudflare and authorize Wrangler.

Terminal window
npm run build

This generates the dist/ folder with your static site.

Terminal window
npx wrangler pages deploy dist

Wrangler uploads the contents of dist/ to Cloudflare Pages .

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.

Every time you want to update the live site:

Terminal window
npm run build
npx wrangler pages deploy dist

A *.pages.dev subdomain works, but a custom domain looks more professional.

  1. In the Cloudflare dashboard, go to Workers & Pages
  2. Click your Pages project
  1. Click the Custom domains tab
  2. Click Set up a custom domain
  3. Enter your domain (e.g., docs.yourdomain.com)
  4. Click Continue

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.dev URL
  • Example: docs → astrodocus.pages.dev

After DNS propagates (5 minutes to 24 hours), your custom domain works with HTTPS automatically.


Once connected to GitHub, Cloudflare Pages watches your repository:

ActionResult
Push to mainProduction deploy
Push to another branchPreview deploy (unique URL)
Open a pull requestPreview deploy with PR comment

This means you never manually deploy again. Just git push, and Cloudflare handles the rest.


When Cloudflare builds your Astro Docus site:

  1. Clones your repository
  2. Installs dependencies (npm install)
  3. Runs npm run build
  4. Reads the dist/ folder
  5. Deploys it to Cloudflare’s global network

The build log shows every step. If something fails, the log tells you exactly where.


ProblemLikely CauseFix
404 errors on *.pages.devMissing index.html at rootCheck that dist/index.html exists
Build failsWrong Node versionSet NODE_VERSION environment variable
Build succeeds but site is blankWrong output directoryVerify dist is set correctly
Wrangler authentication failsToken lacks Pages permissionCreate API token with Cloudflare Pages: Edit scope
Custom domain not workingDNS not propagatedWait longer, or check CNAME record
Slow build timesNo cacheCloudflare caches node_modules/.astro automatically for Astro

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:

VariableValuePurpose
NODE_VERSION20Ensures correct Node.js version
CF_ANALYTICS_TOKENyour tokenCloudflare Web Analytics

Set these before your first deploy if needed.


Method 1 — GitHub Integration (recommended):
1. Sign up at cloudflare.com
2. Workers & Pages → Create application → Pages
3. Connect to Git → Authorize GitHub
4. Select your Astro Docus repository
5. Build settings:
- Build command: npm run build
- Output directory: dist
6. Save and Deploy
7. Your site is live at *.pages.dev
Method 2 — Wrangler Direct Upload:
1. npm install -g wrangler
2. wrangler login
3. npm run build
4. npx wrangler pages deploy dist
5. Live at *.pages.dev
Custom Domain:
- Dashboard → Your project → Custom domains
- Add domain → Configure DNS
- HTTPS automatic

Cloudflare 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.