@sudodevstudio/fastly-for-astro
v0.14.0
Published
Astro v6 adapter for Fastly Compute. Dynamic SSR, server islands, and KV-backed static assets with no app-code changes.
Maintainers
Readme
@sudodevstudio/fastly-for-astro
Astro v6 adapter for Fastly Compute. Dynamic SSR, server islands, and KV-backed static assets — without requiring any changes to your Astro app code.
Install
npm install @sudodevstudio/fastly-for-astroYou also need the Fastly CLI on your machine.
Configure
// astro.config.ts
import { defineConfig } from "astro/config";
import fastlyCompute from "@sudodevstudio/fastly-for-astro";
export default defineConfig({
output: "server",
adapter: fastlyCompute({
aot: true,
kvStoreName: "astro-site-content",
staticCollection: "live",
assetsPrefix: "/_astro/",
securityHeaders: true,
compression: true,
cache: {
staticMaxAge: 31536000,
htmlMaxAge: 0,
staleWhileRevalidate: 60,
},
}),
});That's it. No changes to your pages, components, server islands, or middleware. Running `astro build` automatically generates a Fastly Compute app in `dist/fastly`.
If you use server islands, set a stable ASTRO_KEY in your build environment. Otherwise Astro generates a new encryption key on each build, and old /_server-islands/* URLs can start returning 400 Bad Request after rebuilds or deploys.
Build & deploy
# Build the Astro app — this automatically generates dist/client, dist/server, and dist/fastly
astro build
# Local Fastly Compute dev server from the generated app
cd dist/fastly
npm install
npm run dev:publish
npm run dev:start
# Deploy to Fastly
npm run fastly:deploy
npm run fastly:publish -- --collection-name=liveThe bundled example app in examples/app also includes Astro React integration with:
- a server-rendered React component at
src/components/react/RequestSnapshot.tsx - a client-hydrated React component at
src/components/react/Counter.tsx - a demo page at
/react
If you want Fastly's Ahead-of-Time compiler optimizations in the generated Compute app, set aot: true in the adapter config. That adds --enable-aot to the generated dist/fastly/package.json build script.
Docs
- architecture.md — request flow and build pipeline
- configuration.md — every option, with defaults
- deployment.md — Fastly setup, KV stores, services
- static-assets.md — how assets get to KV
- server-islands.md —
server:deferon the edge - security.md — defaults and how to harden further
- caching.md — cache policy and overrides
- troubleshooting.md — common issues
Limitations
- The Fastly Compute JS runtime is not Node.js. Avoid runtime use of
fs,net,child_process, etc. Build-time use is fine. sharpimage processing is not supported at runtime — usesquooshor a remote image service.- Edge middleware mode (
adapterFeatures.middlewareMode: "edge") is opt-in viaexperimental.edgeMiddleware.
License
MIT
