Astro
Start from CLI: Scaffold an Astro project on Workers, and pick your template.
npm create cloudflare@latest my-astro-app -- --framework=astro --platform=workers
pnpm create cloudflare@latest my-astro-app --framework=astro --platform=workers
yarn create cloudflare my-astro-app --framework=astro --platform=workers
Or just deploy: Create a static blog with Astro and deploy it on Cloudflare Workers, with CI/CD and previews all set up for you.
Astro ↗ is a JavaScript web framework designed for creating websites that display large amounts of content (such as blogs, documentation sites, or online stores).
Astro emphasizes performance through minimal client-side JavaScript - by default, it renders as much content as possible at build time, or on-demand ↗ on the "server" - this can be a Cloudflare Worker. “Islands” ↗ of JavaScript are added only where interactivity or personalization is needed.
Astro is also framework-agnostic, and supports every major UI framework, including React, Preact, Svelte, Vue, SolidJS , via its official integrations ↗.
-
Create a new project with the create-cloudflare CLI (C3).
Terminal window npm create cloudflare@latest -- my-astro-app -- --framework=astro --platform=workersTerminal window pnpm create cloudflare@latest my-astro-app -- --framework=astro --platform=workersTerminal window yarn create cloudflare my-astro-app -- --framework=astro --platform=workersWhat's happening behind the scenes?
When you run this command, C3 creates a new project directory, initiates Astro's official setup tool ↗, and configures the project for Cloudflare. It then offers the option to instantly deploy your application to Cloudflare.
-
Develop locally.
After creating your project, run the following command in your project directory to start a local development server.
Terminal window npm run devTerminal window pnpm run devTerminal window yarn run dev -
Deploy your project.
You can deploy your project to a
*.workers.dev
subdomain or a custom domain from your local machine or any CI/CD system (including Workers Builds). Use the following command to build and deploy. If you're using a CI service, be sure to update your "deploy command" accordingly.Terminal window npm run deployTerminal window pnpm run deployTerminal window yarn run deploy
If your Astro project is entirely pre-rendered, follow these steps:
-
Add a Wrangler configuration file
In your project root, create a Wrangler configuration file with the following content:
{"name": "my-astro-app",// Update to today's date"compatibility_date": "2025-03-25","assets": {"directory": "./dist"}}name = "my-astro-app"compatibility_date = "2025-03-25"[assets]directory = "./dist"What's this configuration doing?
The key part of this config is the
assets
field, which tells Wrangler where to find your static assets. In this case, we're telling Wrangler to look in the./dist
directory. If your assets are in a different directory, update thedirectory
value accordingly. Read about other asset configuration options.Also note how there's no
main
field in this config - this is because you're only serving static assets, so no Worker code is needed for on demand rendering/SSR. -
Build and deploy your project
You can deploy your project to a
*.workers.dev
subdomain or a custom domain from your local machine or any CI/CD system (including Workers Builds). Use the following command to build and deploy. If you're using a CI service, be sure to update your "deploy command" accordingly.Terminal window npx astro buildTerminal window pnpm astro buildTerminal window yarn astro buildTerminal window npx wrangler@latest deployTerminal window pnpm wrangler@latest deployTerminal window yarn wrangler@latest deploy
If your Astro project uses on demand rendering (also known as SSR) ↗, follow these steps:
-
Install the Astro Cloudflare adapter
Terminal window npx astro add cloudflareTerminal window pnpm astro add cloudflareTerminal window yarn astro add cloudflareWhat's happening behind the scenes?
This command installs the Cloudflare adapter and makes the appropriate changes to your
astro.config.mjs
file in one step. By default, this sets the build output configuration tooutput: 'server'
, which server renders all your pages by default. If there are certain pages that don't need on demand rendering/SSR, for example static pages like a privacy policy, you should setexport const prerender = true
for that page or route to pre-render it. You can read more about the adapter configuration options in the Astro docs ↗. -
Add a
.assetsignore
file Create a.assetsignore
file in yourpublic/
folder, and add the following lines to it:_worker.js_routes.json -
Add a Wrangler configuration file
In your project root, create a Wrangler configuration file with the following content:
{"name": "my-astro-app","main": "./dist/_worker.js/index.js",// Update to today's date"compatibility_date": "2025-03-25","compatibility_flags": ["nodejs_compat"],"assets": {"binding": "ASSETS","directory": "./dist"},"observability": {"enabled": true}}name = "my-astro-app"main = "./dist/_worker.js/index.js"compatibility_date = "2025-03-25"compatibility_flags = [ "nodejs_compat" ][assets]binding = "ASSETS"directory = "./dist"[observability]enabled = trueWhat's this configuration doing?
The key parts of this config are:
main
points to the entry point of your Worker script. This is generated by the Astro adaptor, and is what powers your server-rendered pages.assets.directory
tells Wrangler where to find your static assets. In this case, we're telling Wrangler to look in the./dist
directory. If your assets are in a different directory, update thedirectory
value accordingly.
Read more about Wrangler configuration options and asset configuration options.
-
Build and deploy your project
You can deploy your project to a
*.workers.dev
subdomain or a custom domain from your local machine or any CI/CD system (including Workers Builds). Use the following command to build and deploy. If you're using a CI service, be sure to update your "deploy command" accordingly.Terminal window npx astro buildTerminal window pnpm astro buildTerminal window yarn astro buildTerminal window npx wrangler@latest deployTerminal window pnpm wrangler@latest deployTerminal window yarn wrangler@latest deploy
With bindings, your Astro application can be fully integrated with the Cloudflare Developer Platform, giving you access to compute, storage, AI and more. Refer to the bindings overview for more information on what's available and how to configure them.
The Astro docs ↗ provide information about how you can access them in your locals
.
The Astro Cloudflare adapter sets the build output configuration to output: 'server'
, which means all pages are rendered on-demand in your Cloudflare Worker. If there are certain pages that don't need on demand rendering/SSR, for example static pages such as a privacy policy, you should set export const prerender = true
for that page or route to pre-render it. You can read more about on-demand rendering in the Astro docs ↗.
If you want to use Astro as a static site generator, you do not need the Astro Cloudflare adapter. Astro will pre-render all pages at build time by default, and you can simply upload those static assets to be served by Cloudflare.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark