Skip to content
beginner 50 min read ⚡ 350 XP by CMSG Team · Mar 5, 2026
astro cloudflare deployment jamstack

Astro + Cloudflare: The Modern Edge Ritual

Course Overview

Deployment is where your code meets the world. In this course, you will learn to build and deploy an Astro Arcane Glossary A modern web framework designed for high-performance content-driven websites, featuring automatic component hydration logic. application to Cloudflare Pages Arcane Glossary A global cloud network and security provider that hosts websites and provides edge computing services via Workers and Pages. . You will move beyond simple static hosting into Server-Side Rendering (SSR) Arcane Glossary Server-Side Rendering. A technique where a web page is generated on the server for each request, rather than only in the browser. , Edge Functions Arcane Glossary Serverless code that runs globally at 'the edge' (nodes closest to the user) to minimize latency. , and Automated CI/CD Arcane Glossary Continuous Integration and Continuous Deployment. Automated processes for building, testing, and deploying code changes frequently. using the Cloudflare adapter.

Learning Objectives

  • Initialize and configure an Astro Arcane Glossary A modern web framework designed for high-performance content-driven websites, featuring automatic component hydration logic. project for production.
  • Master the Git-based deployment flow to Cloudflare Pages Arcane Glossary A global cloud network and security provider that hosts websites and provides edge computing services via Workers and Pages. .
  • Configure SSR and Edge Adapters for dynamic content performance.
  • Optimize asset delivery using Cloudflare’s Global CDN Arcane Glossary Content Delivery Network. A globally distributed network of servers that caches content close to users to accelerate delivery. .

Prerequisite Rituals

Verify your circle before starting

Check all to unlock lesson focus READY TO CAST

Technical Deep Dive: The Cloudflare Edge

Unlike traditional servers, Cloudflare Pages runs on their Global Network.

  • Static Content: Served directly from 300+ nodes, ensuring sub-50ms latency globally.
  • SSR & Functions: Uses Cloudflare Workers (V8 isolates) which boot in <5ms, far faster than traditional AWS Lambda or Google Cloud Functions cold starts.

Walkthrough: Building and Deploying your First Ritual

Step 1: Initialize the Arcane Site

We’ll use the Astro CLI to scaffold a high-performance baseline.

npm create astro@latest my-arcane-site -- --template minimal --install --git --no-typescript
cd my-arcane-site

Step 2: Configure the Cloudflare Adapter

To use dynamic features (like forms or auth), we need the Cloudflare adapter.

npx astro add cloudflare

This command automatically modifies your astro.config.mjs to include the cloudflare integration:

import { defineConfig } from 'astro/config';
import cloudflare from "@astrojs/cloudflare";

export default defineConfig({
  output: 'server', // Enable SSR
  adapter: cloudflare()
});

Step 3: Git-Based Deployment

Push your code to GitHub.

git add .
git commit -m "chore: prepare for edge deployment"
# Create a repo on GitHub and follow their 'push existing' commands

Step 4: The Cloudflare Dashboard Ritual

  1. Log in to dash.cloudflare.com.
  2. Navigate to Workers & Pages > Create application > Pages > Connect to Git.
  3. Select your repository.
  4. Build settings:
    • Framework preset: Astro
    • Build command: npm run build
    • Build output directory: dist
  5. Environment Variables: Add NODE_VERSION set to 22 for the best performance.
  6. Click Save and Deploy.

Pro Optimization: The Deployment Health Ritual

  • Preview Deployments: Every branch you push will get a unique URL. Use this for testing before merging to main.
  • Custom Domains: Connect your .com via the “Custom Domains” tab for a professional finish.
  • Cache Control: Astro automatically fingerprints assets. Cloudflare handles the rest, but you can configure complex caching headers in a _headers file.

Capstone Project: The Edge-Powered Portfolio

Create a personal portfolio that uses at least one dynamic feature.

  1. Implement a Server-Side Dynamic Route (e.g., /api/status) that returns the current server time.
  2. Deploy the site to Cloudflare Pages.
  3. Configure a Custom Domain (optional) and verify the SSL Certificate is active.

The site is live. It exists on every continent simultaneously. You are a global architect.

📜 The Grimoire

Progress to Adept 0%
Knowledge Acquired

No spells mastered yet...

Rank Hierarchy

Progress saved locally to your browser.

🕯️ Academy Support

Common Ritual Issues
"Node.js version not found"
Run node -v. If it's below 22.12.0, use NVM to upgrade: nvm install 22 && nvm use 22
"Build fails on Cloudflare"
Ensure you've set the NODE_VERSION environment variable to 22.12.0 in the Cloudflare Dashboard settings.
"Prerequisites not checking"
The checklists are interactive but local to your current lesson view. They help you track your own setup progress manually.

Still blocked by a technical curse?

Ask the Archmage