Skip to content

Deploy an Astro site to Cloudflare Workers

A static Astro site needs no adapter: a four-line wrangler.jsonc and wrangler deploy. When pages render on request, add @astrojs/cloudflare. Both tested.

Updated 23 November 2026Tested with
  • Astro 7.4.13
  • @astrojs/cloudflare 14.4.9
  • Wrangler 4.166.0

A static Astro site goes on Cloudflare Workers with no adapter: build it, point a small wrangler.jsonc at the dist folder and run npx wrangler deploy. You only add @astrojs/cloudflare when pages render on request. Cloudflare now recommends Workers over Pages for new projects, so that's what this guide uses. Both routes below were tested on Astro 7.4.13 with Wrangler 4.166, up to the dry run before upload.

Our Astro themes are static by default, so most people want the first route.

Route 1: a static site (no adapter)

  1. Step 1: Build the site

    Terminal
    npm run build[build] Complete!

    Everything is now in dist/: HTML, CSS, JavaScript and images.

  2. Step 2: Add a wrangler.jsonc

    In the project root. The name becomes your *.workers.dev subdomain; the compatibility date can be today's.

    wrangler.jsoncJSON
    {  "name": "my-astro-site",  "compatibility_date": "2026-11-20",  "assets": {    "directory": "./dist",    "not_found_handling": "404-page"  }}

    There's no main entry, so no Worker code runs: Cloudflare serves the files directly. "404-page" makes missing URLs return your 404.html with a real 404 status.

  3. Step 3: Check it with a dry run

    Terminal
    npx wrangler deploy --dry-run✨ Read 5 files from the assets directory …/distTotal Upload: 0.37 KiB / gzip: 0.26 KiBNo bindings found.--dry-run: exiting now.

    If the file count looks wrong, the build didn't run or directory points somewhere else.

  4. Step 4: Deploy

    The first time, Wrangler opens a browser to log in to your Cloudflare account (npx wrangler login does the same on its own). Then:

    Terminal
    npx wrangler deploy

    It prints the workers.dev URL when it's done. Add a script so you don't have to remember the order: "deploy": "astro build && wrangler deploy".

Route 2: pages rendered on request (with the adapter)

Use this when some pages need the request: a form handler, a page behind login, an API route. Add the adapter with Astro's own command:

Terminal
npx astro add cloudflare -y   success  Added the following integration to your project:  - @astrojs/cloudflare

In our test that did three things: added @astrojs/cloudflare 14.4.9 and wrangler to the project, set adapter: cloudflare() in astro.config.mjs, and wrote a wrangler.jsonc for you:

wrangler.jsoncJSON
{  "$schema": "./node_modules/wrangler/config-schema.json",  "compatibility_date": "2026-11-17",  "compatibility_flags": ["global_fetch_strictly_public"],  "name": "my-astro-site",  "main": "@astrojs/cloudflare/entrypoints/server",  "assets": { "directory": "./dist", "binding": "ASSETS" },  "observability": { "enabled": true }}

Pages stay prerendered unless you opt out per page:

src/pages/now.astroAstro
---export const prerender = false;const time = new Date().toISOString();---<p>Rendered on request at {time}</p>

Build and dry-run as before. The adapter writes the final Wrangler config into the build, so wrangler deploy picks it up from there:

Terminal
npm run build && npx wrangler deploy --dry-runTotal Upload: 478.05 KiB / gzip: 131.41 KiBYour Worker has access to the following bindings:Binding             Resourceenv.SESSION         KV Namespaceenv.IMAGES          Imagesenv.ASSETS          Assets

Two bindings appear that you didn't write. SESSION is a KV namespace for Astro sessions and IMAGES is Cloudflare's image service, both wired up by the adapter. The KV binding has no ID; Wrangler provisions it on the first real deploy.

Deploy on every push

In the Cloudflare dashboard, open your Worker, go to Settings, then Builds, and connect the GitHub or GitLab repository. Set the build command to npm run build and the deploy command to npx wrangler deploy. Every push to the production branch then builds and deploys; with preview builds on, other branches get a Preview with its own URL instead of touching the live site.

One rule that fails builds: the Worker's name in the dashboard must match name in your wrangler.jsonc. Cloudflare's docs call this out, and it's the first thing to check when a connected build stops at the deploy step.

A CMS can trigger the same build: under Settings, Builds, Deploy Hooks you get a URL that starts a build when it receives a POST. That's how a static site picks up a published change from Sanity or another headless CMS.

Your own domain

If the domain's DNS is on Cloudflare, add it under the Worker's Settings, Domains & Routes, as a custom domain. Cloudflare creates the DNS record and the certificate. You can also put it in wrangler.jsonc:

wrangler.jsoncJSON
"routes": [{ "pattern": "www.example.com", "custom_domain": true }]

Questions

Do I need @astrojs/cloudflare for a static Astro site?

No. A static build is just files, and Workers static assets serves them with the four-line config above. The adapter is for on-demand rendering.

Why does my deploy upload old pages?

wrangler deploy doesn't build. It uploads whatever is in dist/. Run the build first, or use a deploy script that does both.

Does this work for themes.dev templates?

Yes. Our Astro themes build to static files and come with a wrangler.jsonc for route 1 already in the repository, plus a netlify.toml for Netlify. Give the Worker your own name, build with SITE_URL=https://www.example.com set so canonical links and the sitemap use your domain, and run npx wrangler deploy. From template to live site walks through the whole path.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components. They ship in the next UI Pro release; the install command and the contents rail are free.