Skip to main content
Mastra 1.0 is available 🎉 Read announcement

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.

Installation
Direct link to Installation

To use CloudflareDeployer, install the @mastra/deployer-cloudflare package:

npm install @mastra/deployer-cloudflare@latest

Usage example
Direct 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 options
Direct 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 output
Direct 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.

On this page