Astro
Use Void with Astro for resource detection, typed database queries, and migrations.
Use Astro 7 or later.
Setup
1. Create a new project
npm create astro@latest my-app
cd my-app2. Install dependencies
npm install -D @astrojs/cloudflare void3. Configure astro.config.mjs
import cloudflare from '@astrojs/cloudflare';
import { defineConfig } from 'astro/config';
import { voidPlugin } from 'void';
export default defineConfig({
adapter: cloudflare({ configPath: './.void-wrangler.jsonc' }),
vite: { plugins: [voidPlugin()] },
});4. Create void.config.ts
import { defineConfig } from 'void/config';
export default defineConfig({
cloudflare: {
name: 'my-app',
compatibility_date: '2026-02-24',
compatibility_flags: ['nodejs_als'],
},
});nodejs_als is required for void/* runtime helpers (for example void/db, void/kv) in Astro.
5. Deploy
void connect --platform cloudflare
void deployvoid connect signs you in to Cloudflare, asks which account to use, and saves it as the deploy target. To deploy to a Void platform run by your team instead, see Deployment.
On your own Cloudflare account, Void deploys an Astro app as a Worker, and Astro only builds one when a route sets export const prerender = false or output is 'server'. If every page is prerendered, which is Astro's default, build the site and deploy its files instead:
npm run build
void deploy --dir dist/clientUsing Void Features
Use Void resources in server-rendered pages and API routes. For authentication, use your framework’s Better Auth integration.
Pages and API routes that access runtime bindings must opt out of prerendering:
---
export const prerender = false;
---Database
For an API route that returns the current list of users, query the users table on each request.
import { users } from '@schema';
import type { APIRoute } from 'astro';
import { db } from 'void/db';
export const prerender = false;
export const GET: APIRoute = async () => {
const rows = await db.select().from(users);
return Response.json(rows);
};Other resources
See supported resources and background jobs for KV, storage, AI, cron jobs, and queues.
Environment Variables
Declare variables in env.ts and read them with import { env } from "void/env". See Environment Variables for local values, production secrets, and public VITE_* values.
Use VITE_* for public keys in the Void schema. Astro’s PUBLIC_* prefix applies to import.meta.env.
Accessing Bindings Directly
Access bindings with env from cloudflare:workers (works in both dev and production):
import type { APIRoute } from 'astro';
import { env } from 'cloudflare:workers';
export const prerender = false;
export const GET: APIRoute = async () => {
const { results } = await env.DB.prepare('SELECT * FROM users').all();
return Response.json(results);
};In .astro pages (remember to set prerender = false):
---
import { env } from 'cloudflare:workers';
export const prerender = false;
const { results } = await env.DB.prepare("SELECT * FROM users").all();
---