docs/src/content/en/reference/deployer/cloudflare.mdx
The CloudflareDeployer bundles your Mastra server and generates a wrangler.jsonc file conforming to Cloudflare's wrangler configuration. Cloudflare deploys this as a Cloudflare Worker.
To use CloudflareDeployer, install the @mastra/deployer-cloudflare package:
npm install @mastra/deployer-cloudflare@latest
Import CloudflareDeployer and set it as the deployer in your Mastra configuration:
import { Mastra } from '@mastra/core'
import { CloudflareDeployer } from '@mastra/deployer-cloudflare'
export const mastra = new Mastra({
deployer: new CloudflareDeployer({
name: 'your-project-name',
routes: [
{
pattern: 'example.com/*',
zone_name: 'example.com',
custom_domain: true,
},
],
vars: {
NODE_ENV: 'production',
},
d1_databases: [
{
binding: 'DB',
database_name: 'my-database',
database_id: 'd1-database-id',
preview_database_id: 'your-preview-database-id',
},
],
kv_namespaces: [
{
binding: 'CACHE',
id: 'kv-namespace-id',
},
],
}),
})
The CloudflareDeployer constructor accepts the same configuration options as wrangler.jsonc. See the Wrangler configuration documentation for all available options.
Environment variables from your .env file are not written to wrangler.jsonc. This prevents secrets from being committed to source control.
To make your .env secrets available to your Cloudflare Worker, upload them as Cloudflare Secrets:
npx wrangler secret bulk .env
Use vars in the CloudflareDeployer constructor only for non-sensitive configuration values like NODE_ENV.
After running mastra build, the deployer generates a wrangler.jsonc file conforming to Cloudflare's wrangler configuration. It points to files inside .mastra/output so you need to run mastra build before deploying with Wrangler.