CloudflareDeployer
The CloudflareDeployer
class handles deployment of standalone Mastra applications to Cloudflare Workers. It manages configuration, deployment, and extends the base Deployer class with Cloudflare specific functionality.
Usage example
src/mastra/index.ts
import { Mastra } from "@mastra/core/mastra";
import { CloudflareDeployer } from "@mastra/deployer-cloudflare";
export const mastra = new Mastra({
// ...
deployer: new CloudflareDeployer({
scope: "your-account-id",
projectName: "your-project-name",
routes: [
{
pattern: "example.com/*",
zone_name: "example.com",
custom_domain: true,
},
],
workerNamespace: "your-namespace",
auth: {
apiToken: "your-api-token",
apiEmail: "your-email",
},
d1Databases: [
{
binding: "binding-name",
database_name: "database-name",
database_id: "database-id",
},
],
kvNamespaces: [
{
binding: "binding-name",
id: "namespace-id",
},
],
}),
});
Parameters
Constructor Parameters
scope:
string
Your Cloudflare account ID.
projectName?:
string
= 'mastra'
Name of your worker project.
routes?:
CFRoute[]
Array of route configurations for your worker.
workerNamespace?:
string
Namespace for your worker.
env?:
Record<string, any>
Environment variables to be included in the worker configuration.
auth:
object
Cloudflare authentication details.
d1Databases?:
D1DatabaseBinding[]
Array of D1 database bindings for your worker.
kvNamespaces?:
KVNamespaceBinding[]
Array of KV namespace bindings for your worker.
auth Object
apiToken:
string
Your Cloudflare API token.
apiEmail?:
string
Your Cloudflare account email.
CFRoute Object
pattern:
string
URL pattern to match (e.g., 'example.com/*').
zone_name:
string
Domain zone name.
custom_domain?:
boolean
= false
Whether to use a custom domain.
D1DatabaseBinding Object
binding:
string
Name used in Worker code (e.g., `env.testdb`).
database_name:
string
Human-readable name (for dashboard).
database_id:
string
Cloudflare D1 database ID.
preview_database_id?:
string
For preview deployments.
KVNamespaceBinding Object
binding:
string
Name used in Worker code (e.g., `env.test_namespace`).
id:
string
Cloudflare KV namespace ID.