CloudflareDeployer
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.
InstallationDirect link to Installation
To use CloudflareDeployer, install the @mastra/deployer-cloudflare package:
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/deployer-cloudflare@latest
pnpm add @mastra/deployer-cloudflare@latest
yarn add @mastra/deployer-cloudflare@latest
bun add @mastra/deployer-cloudflare@latest
Usage exampleDirect link to Usage example
Import CloudflareDeployer and set it as the deployer in your Mastra configuration:
src/mastra/index.ts
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",
API_KEY: "<api-key>"
},
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"
}
]
})
});
Constructor optionsDirect link to Constructor options
The CloudflareDeployer constructor accepts the same configuration options as wrangler.jsonc. See the Wrangler configuration documentation for all available options.
Build outputDirect link to Build output
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.