Deploy to Cloudflare Workers

beginner CloudflaredeploymenthostingAstro

Cloudflare Workers with Static Assets is the modern way to host static sites on Cloudflare’s global network. It replaces Cloudflare Pages, which is being deprecated. The free tier covers 100,000 requests per day — plenty for a personal tutorial site.

Cloudflare Pages is deprecated

If you see “Create a Pages project” in the dashboard, use the Workers path instead. Pages is being retired in favour of Workers with Static Assets.

Prerequisites

Step 1 — Configure wrangler.toml

The wrangler.toml file at the project root tells Wrangler where your built files live. This repo already has it configured, but for reference it should look like this:

name = "dev-tutorials"
compatibility_date = "2026-04-07"

[assets]
directory = "./dist"

The [assets] section is the Workers Static Assets format. The old [site] format was for a legacy product called Workers Sites — do not use it.

Step 2 — Log in to Cloudflare

Authenticate Wrangler with your Cloudflare account:

npx wrangler login

This opens a browser window. Log in and click Allow. Wrangler stores a token locally so you don’t need to repeat this step.

Cloudflare dashboard login page

Step 3 — Build the site

Generate the static output and Pagefind search index:

npm run build

This runs astro build followed by pagefind --site dist. Both outputs land in dist/ — that’s what gets deployed.

Step 4 — Deploy

npx wrangler deploy

Wrangler reads wrangler.toml, uploads the contents of dist/ to Cloudflare’s network, and prints your live URL:

Uploaded dev-tutorials (1.23 sec)
Deployed dev-tutorials triggers (0.42 sec)
  https://dev-tutorials.YOUR_SUBDOMAIN.workers.dev

Your site is now live on Cloudflare’s global CDN.

First deploy creates the Worker

The first wrangler deploy creates the Worker in your Cloudflare account automatically — no dashboard setup required.

Step 5 — Connect GitHub for automatic deploys

Rather than running wrangler deploy manually on every change, connect your GitHub repository through the Cloudflare dashboard for automatic deploys on every push.

  1. In the Workers & Pages dashboard, open your Worker
  2. Go to Settings → Build (or Deployments → Connect to Git)
  3. Click Connect a repository and authorise Cloudflare to access your GitHub account
  4. Select your repository and branch (main)
  5. Set the build command to npm run build and the output directory to dist
  6. Click Save

From this point, every push to main triggers a build and deploy automatically — no API tokens or GitHub Actions required.

Optional — Custom domain

To serve from your own domain instead of *.workers.dev:

  1. In the Cloudflare dashboard, open Workers & Pages and select your Worker
  2. Go to Settings → Triggers → Custom Domains
  3. Click Add Custom Domain and enter your domain

SSL is provisioned automatically.

What gets deployed

The npm run build script runs two commands:

astro build    → generates static HTML/CSS/JS into dist/
pagefind       → builds the full-text search index into dist/pagefind/

Both land in dist/, which wrangler deploy uploads in full. Search works on the live site because the Pagefind index files are included in the deployment.