Cloudflare Pages
Deploy to Cloudflare’s global edge network.
Quick Deploy
Section titled “Quick Deploy”-
Push your code to GitHub or GitLab
-
Log in to Cloudflare Dashboard
-
Go to Pages → Create a project
-
Connect your repository
-
Configure build settings
-
Deploy
CLI Deployment
Section titled “CLI Deployment”# Install Wrangler CLIpnpm add -g wrangler
# Loginwrangler login
# Buildpnpm build
# Deploywrangler pages deploy distBuild Settings
Section titled “Build Settings”Configure in Cloudflare Dashboard:
| Setting | Value |
|---|---|
| Framework Preset | Astro |
| Build Command | pnpm build |
| Build Output | dist |
| Node Version | 22 |
Server-Side Features
Section titled “Server-Side Features”For SSR and API routes, add the Cloudflare adapter:
pnpm add @astrojs/cloudflareimport cloudflare from '@astrojs/cloudflare';
export default defineConfig({ output: 'server', adapter: cloudflare(),});Environment Variables
Section titled “Environment Variables”Set in Pages → Project → Settings → Environment Variables:
SITE_URL=https://your-project.pages.devPUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXXCustom Domain
Section titled “Custom Domain”- Go to Pages → Your Project → Custom Domains
- Add your domain
- Configure DNS (Cloudflare handles this automatically if domain is on CF)
Workers
Section titled “Workers”For advanced serverless:
export async function onRequest(context) { return new Response(JSON.stringify({ message: 'Hello!' }), { headers: { 'Content-Type': 'application/json' }, });}KV Storage
Section titled “KV Storage”Use Cloudflare KV for data:
export default defineConfig({ adapter: cloudflare({ mode: 'directory', functionPerRoute: true, }),});// In your API routeexport async function GET({ locals }) { const value = await locals.runtime.env.MY_KV.get('key'); return new Response(value);}Preview Deployments
Section titled “Preview Deployments”Branch deploys create preview URLs:
branch-name.your-project.pages.dev
Troubleshooting
Section titled “Troubleshooting”Node Version
Section titled “Node Version”Set in dashboard or wrangler.toml:
node_compat = trueBuild Failures
Section titled “Build Failures”Check build logs in Pages dashboard.
API Routes Not Working
Section titled “API Routes Not Working”Ensure output: 'server' is set and adapter is configured.