plan March 10, 2024
Deploying Astro to Cloudflare Workers: Architecture Plan
A structured plan for deploying an Astro hybrid SSR application to Cloudflare Workers.
#astro #cloudflare #devops #architecture
Deploying Astro to Cloudflare Workers: Architecture Plan
Overview
Cloudflare Workers runs JavaScript at the edge, globally distributed, with zero cold starts. Combined with Astro’s hybrid output mode, we get static pages for content and server-rendered pages for dynamic functionality.
Architecture Decision
output: 'hybrid'
├── Static pages (prerendered at build time)
│ ├── /ideas/[slug] → prerendered MDX
│ └── / → static homepage
└── Server pages (rendered on each request)
├── /lab/* → dynamic tools
└── /api/* → API routesConfiguration Checklist
-
@astrojs/cloudflareadapter installed -
output: 'hybrid'set in astro.config -
platformProxy.enabled: truefor local dev -
wrangler.jsoncconfigured - KV namespace bound for caching (optional)
- D1 database bound if needed
Build & Deploy Commands
npm run build # builds to dist/
wrangler deploy # deploys to CloudflarePerformance Notes
- Workers have a 128MB memory limit — avoid large imports
- Use
export const prerender = trueon static pages - Images should be served from Cloudflare Images or R2
- Environment variables set via
wrangler secret put VAR_NAME
Known Limitations
sharpimage processing is incompatible with Workers — usesquooshor disable image processing- Node.js APIs unavailable unless using
nodejs_compatcompatibility flag