Skip to main content

CloudflareDeployer

CloudflareDeployer 类负责将独立的 Mastra 应用部署到 Cloudflare Workers。它管理配置和部署,并通过 Cloudflare 特定功能扩展了基础的 Deployer 类。

🌐 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.

使用示例
Direct link to 使用示例

🌐 Usage example

src/mastra/index.ts
import { Mastra } from "@mastra/core";
import { CloudflareDeployer } from "@mastra/deployer-cloudflare";

export const mastra = new Mastra({
deployer: new CloudflareDeployer({
name: "hello-mastra",
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"
}
]
})
});

构造函数选项
Direct link to 构造函数选项

🌐 Constructor options

CloudflareDeployer 构造函数接受与 wrangler.json 相同的配置选项。有关所有可用选项,请参阅 Wrangler 配置文档

🌐 The CloudflareDeployer constructor accepts the same configuration options as wrangler.json. See the Wrangler configuration documentation for all available options.

从早期版本迁移
Direct link to 从早期版本迁移

🌐 Migrating from earlier versions

以下字段已弃用,应使用其标准 wrangler.json 等效项替换:

🌐 The following fields are deprecated and should be replaced with their standard wrangler.json equivalents:

已弃用请改用
projectNamename
d1Databasesd1_databases
kvNamespaceskv_namespaces
workerNamespace(已删除,不再使用)