CloudflareDeployer
CloudflareDeployer
クラスは、スタンドアロンのMastraアプリケーションをCloudflare Workersにデプロイすることを処理します。設定とデプロイメントを管理し、Cloudflare固有の機能でベースのDeployerクラスを拡張します。
使用例
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",
},
],
}),
});
パラメータ
コンストラクタパラメータ
scope:
string
あなたのCloudflareアカウントID。
projectName?:
string
= 'mastra'
ワーカープロジェクトの名前。
routes?:
CFRoute[]
ワーカーのルート設定の配列。
workerNamespace?:
string
ワーカーの名前空間。
env?:
Record<string, any>
ワーカー設定に含める環境変数。
auth:
object
Cloudflare認証の詳細。
d1Databases?:
D1DatabaseBinding[]
ワーカーのD1データベースバインディングの配列。
kvNamespaces?:
KVNamespaceBinding[]
ワーカーのKV名前空間バインディングの配列。
authオブジェクト
apiToken:
string
あなたのCloudflare APIトークン。
apiEmail?:
string
あなたのCloudflareアカウントのメールアドレス。
CFRouteオブジェクト
pattern:
string
マッチするURLパターン(例:'example.com/*')。
zone_name:
string
ドメインゾーン名。
custom_domain?:
boolean
= false
カスタムドメインを使用するかどうか。
D1DatabaseBindingオブジェクト
binding:
string
Workerコードで使用される名前(例:`env.testdb`)。
database_name:
string
人間が読める名前(ダッシュボード用)。
database_id:
string
Cloudflare D1データベースID。
preview_database_id?:
string
プレビューデプロイメント用。
KVNamespaceBindingオブジェクト
binding:
string
Workerコードで使用される名前(例:`env.test_namespace`)。
id:
string
Cloudflare KV名前空間ID。