Deploying Astro to Cloudflare Workers

· Siddhartha Varma
astro cloudflare deployment tutorial

Deploying Astro to Cloudflare Workers

Astro is a fantastic static site generator, and when combined with Cloudflare Workers, you get a blazing-fast website distributed globally across Cloudflare’s edge network.

Why Cloudflare Workers?

Cloudflare Workers provide several advantages:

  • Global CDN: Your site is served from the nearest edge location to your users
  • Fast: Extremely low latency with edge caching
  • Free Tier: Generous free tier for personal projects
  • Easy Deployment: Simple deployment process with Wrangler CLI

Setup Steps

1. Install the Cloudflare Adapter

npm install @astrojs/cloudflare

2. Configure Astro

Update your astro.config.mjs:

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

export default defineConfig({
  output: 'static',
  adapter: cloudflare({
    mode: 'directory',
  }),
});

3. Create wrangler.toml

Create a wrangler.toml file in your project root:

name = "my-portfolio"
compatibility_date = "2026-01-29"
pages_build_output_dir = "./dist"

[site]
bucket = "./dist"

4. Deploy

Build your site and deploy:

npm run build
wrangler pages publish dist

That’s it! Your Astro site is now deployed on Cloudflare Workers.

Next Steps

  • Set up custom domains
  • Configure redirects and headers
  • Add analytics
  • Enable caching strategies

Happy deploying!

Markdown copied to clipboard