@recranet/astro-workers-for-platforms-adapter
v1.2.0
Published
Custom Astro adapter for Cloudflare Workers for Platforms.
Readme
astro-workers-for-platforms-adapter
Custom Astro adapter for Cloudflare Workers for Platforms.
How it works
Request → Dispatch Worker → User Worker (worker-entry.mjs) → env.ASSETS.fetch()This adapter ensures Astro always emits a worker entry, even for fully static sites. While static assets could be uploaded to R2 and served by the dispatch worker.
Workers for Platforms supports a native Static Assets binding (env.ASSETS) that serves files from the edge with per-tenant isolation — no R2 needed.
Running astro build produces two outputs: a bundled worker at dist/server/entry.mjs and static assets in dist/client/. The adapter sets ssr.noExternal: true so Vite inlines all dependencies into a single file with no external imports.
Deployment uses the Workers for Platforms asset upload API in three steps: create session, upload asset buckets, then deploy the worker with a completion token.
Why not @astrojs/cloudflare?
The official @astrojs/cloudflare adapter cannot be used here because:
- It requires wrangler as a peer dependency (we deploy programmatically via the API, not with wrangler)
- As of Astro 6, it deletes
_worker.jsfor fully static sites — Workers for Platforms always needs a worker entry
Getting started
npm install @recranet/astro-workers-for-platforms-adapter// astro.config.mjs
import { defineConfig } from 'astro/config';
import astroWorkersForPlatformsAdapter from '@recranet/astro-workers-for-platforms-adapter';
export default defineConfig({
adapter: astroWorkersForPlatformsAdapter(),
});