Deploying Your Astro Blog to Cloudflare Workers
17124
Deploying Your Astro Blog to Cloudflare Workers
Cloudflare Workers provides a serverless edge runtime that's perfect for Astro SSR sites. Combined with D1 for the database and R2 for storage, you get a fully managed stack.
Prerequisites
- A Cloudflare account
- Wrangler CLI installed
- An Astro project with
@astrojs/cloudflareadapter
Step 1: Install the Adapter
npm install @astrojs/cloudflareUpdate astro.config.mjs:
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
output: 'server',
adapter: cloudflare(),
});Step 2: Create D1 Database
wrangler d1 create my-databaseAdd the binding to wrangler.toml:
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "<your-database-id>"Step 3: Deploy
npm run build
wrangler deployYour site is now live at https://your-worker.workers.dev!
Comments
Loading comments...