Skip to content

Guide

Deploying Astro to the Edge: Cloudflare, Vercel and Netlify with Velocity

A practical guide to shipping an Astro site to the edge, what a Velocity project includes for Cloudflare, Vercel and Netlify, and when you actually need an adapter.

Guide No. 02

“Deploy to the edge” gets said a lot, and it can mean two different things. Sometimes it means static files served from a CDN close to your visitors. Sometimes it means your server code runs in a lightweight runtime in many locations. Most Astro sites need the first, a few need the second, and mixing them up leads to setup you don’t need or forms that quietly stop working.

This guide covers both, using a Velocity project as it ships today in the v0.1.0 beta.

Why this came up now

In January, Cloudflare announced that the Astro core team is joining the company. We wrote about what that means on the Southwell Media blog: Astro + Cloudflare: Why Southwell Media is All-In on Edge-Native Development.

Two points from that post matter for anyone deploying Astro:

  • The framework stays open source under the MIT license, and it stays platform-agnostic. Vercel, Netlify and your own servers remain supported targets.
  • The Astro 6 beta, which Velocity is built on, can run the dev server inside workerd, the runtime Cloudflare Workers uses. Code that works locally is running in the same engine it will meet in production.

So the question isn’t which host Astro prefers. It’s which kind of deployment your site needs.

Start static

Velocity’s astro.config.mjs sets no output mode and no adapter. That means pnpm build prerenders every page to plain files in dist/, and any static host can serve them. The README says it directly:

pnpm build

Build outputs to dist/ for any static host.

A static dist/ behind Cloudflare, Vercel or Netlify is already served from their edge networks. For a marketing site, docs or a blog, that’s usually the right answer: no server to run, nothing to cold-start, and the cheapest possible hosting.

Set SITE_URL before you build. The config reads it for site, and .env.example notes it’s used for the sitemap, canonical URLs and OG images:

site: process.env.SITE_URL || 'https://example.com',

What ships for each platform

The repository includes a config file for each of the three hosts the README lists:

PlatformFileWhat it sets
Cloudflarewrangler.tomlProject name velocity, a compatibility date, and ./dist as the asset directory
Vercelvercel.jsonpnpm run build, dist as output, framework astro, security headers, long-lived caching for /_astro/* and /fonts/*
Netlifynetlify.tomlpnpm run build, publish dist, Node 22, the same headers and caching rules

The README gives one command per platform:

vercel                         # Vercel
netlify deploy --prod          # Netlify
wrangler pages deploy dist     # Cloudflare Pages

Rename the project in wrangler.toml before your first Cloudflare deploy. It’s velocity out of the box, and the commented Cloudflare step in the CI workflow uses the same --project-name=velocity.

The immutable caching rule is safe because Astro fingerprints the files it writes to /_astro/. A changed file gets a new name, so browsers and CDNs can keep the old one for a year without serving stale code.

Cloudflare doesn’t read vercel.json or netlify.toml, so the template’s security headers don’t carry over there. If you deploy to Cloudflare Pages, see their headers documentation for setting them with a _headers file in public/.

Deploying from CI

.github/workflows/deploy.yml runs on pushes and pull requests to main. It installs with pnpm on Node 22, then runs lint, type check and build, passing SITE_URL from a repository secret.

The deploy step itself is left to you. The workflow ends with commented-out steps for Vercel, Netlify and Cloudflare Pages, each reading its tokens from secrets. Uncomment the one you use, add the secrets in GitHub, and every merge to main builds, checks and deploys.

If you’d rather let the host build from Git directly, connect the repository in its dashboard instead. The config files above give it the build command and output directory.

When you need an adapter

Velocity includes two API routes, src/pages/api/contact.ts and src/pages/api/newsletter.ts. Both export a POST handler that validates form data with Zod. In a fully static build there’s no server to answer a POST, so these routes need two things before they work in production:

  1. An adapter for your host.
  2. export const prerender = false in each route, so Astro renders it on demand instead of at build time.

Add the adapter with one command:

npx astro add cloudflare   # or: vercel, netlify

This installs @astrojs/cloudflare, @astrojs/vercel or @astrojs/netlify and adds it to astro.config.mjs. Every other page stays prerendered. Only the routes you opt out run on the server, which on Cloudflare means Workers, and on Vercel and Netlify means their functions.

// src/pages/api/contact.ts
export const prerender = false;

The official guides cover the details per host: Cloudflare, Vercel and Netlify. For on-demand rendering in general, see the Astro docs.

Things to check when you switch

A few settings in the shipped files were written for static output. Review them once you add an adapter:

  • Netlify: netlify.toml rewrites /api/* to /.netlify/functions/:splat. The template doesn’t define any Netlify functions, so make sure that rule doesn’t get between requests and the Astro routes.
  • Vercel: the adapter produces Vercel’s build output itself. Revisit the static outputDirectory in vercel.json when you switch, and check the Vercel docs for the current setup.
  • Cloudflare: set your own compatibility_date and follow the adapter guide for the Wrangler config it expects.
  • Secrets: the contact endpoint is a stub. It validates, checks a honeypot field and logs in development, but doesn’t send anything yet. When you wire it to a real service, keep keys server-side. .env.example reminds you that anything prefixed PUBLIC_ is exposed to the browser.

Which one to pick

If your site has no forms or only uses third-party form services, stay static and pick whichever host you like. All three serve dist/ from their edge networks.

If you need the API routes, add the adapter for the host you’re already on. If you’re starting fresh and want the closest match between local development and production, the Cloudflare adapter with the Astro 6 dev server running in workerd is the strongest reason to choose it.

Velocity is on GitHub, and you can scaffold a project with create-velocity-astro.

All posts
Share:

Related posts