メインコンテンツへ移動

NetlifyDeployer

NetlifyDeployer クラスは、Mastra の出力を調整して最適化されたサーバーを作成し、パッケージ化、設定、デプロイを処理します。基底クラスの Deployer を Netlify 固有の機能で拡張しています。これにより、Netlify のサーバーレス関数または Edge Functions 内で Mastra を実行できます。

インストール
インストールへの直接リンク

NetlifyDeployer を使用するには、@mastra/deployer-netlify パッケージをインストールする必要があります。

npm install @mastra/deployer-netlify@latest

使用例
使用例への直接リンク

NetlifyDeployer をインポートし、Mastra 設定で deployer に指定します。

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { NetlifyDeployer } from '@mastra/deployer-netlify'

export const mastra = new Mastra({
deployer: new NetlifyDeployer(),
})

コンストラクターオプション
コンストラクターオプションへの直接リンク

  • target?: 'serverless' | 'edge':Netlify のデプロイ先です。デフォルトは 'serverless' です。
    • 'serverless':標準の Netlify Functions(Node.js ランタイム、デフォルトのタイムアウトは 60 秒)。
    • 'edge'Netlify Edge Functions(Deno ベースのランタイムで、ユーザーに最も近いエッジで実行され、固定のタイムアウトはありません)。

Edge Functions の例
Edge Functions の例への直接リンク

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { NetlifyDeployer } from '@mastra/deployer-netlify'

export const mastra = new Mastra({
deployer: new NetlifyDeployer({
target: 'edge',
}),
})

出力
出力への直接リンク

mastra build を実行すると、deployer は .netlify フォルダーを生成します。ビルド出力にはプロジェクトのすべての Agent、Tool、Workflow に加え、Netlify Frameworks API を設定する config.json ファイルが含まれます。

サーバーレス出力(デフォルト)
サーバーレス出力(デフォルト)への直接リンク

your-project/
└── .netlify/
└── v1/
├── config.json
└── functions/
└── api/
├── index.mjs
├── package.json
└── node_modules/

config.json ファイルの内容は次のとおりです。

{
"functions": {
"directory": ".netlify/v1/functions",
"node_bundler": "none",
"included_files": [".netlify/v1/functions/**"]
},
"redirects": [
{
"force": true,
"from": "/*",
"to": "/.netlify/functions/api/:splat",
"status": 200
}
]
}

Edge 出力
Edge 出力への直接リンク

your-project/
└── .netlify/
└── v1/
├── config.json
└── edge-functions/
├── index.mjs
├── package.json
└── node_modules/

config.json ファイルの内容は次のとおりです。

{
"edge_functions": [
{
"function": "index",
"path": "/*"
}
]
}