跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

NetlifyDeployer

The NetlifyDeployer class handles packaging, configuration, and deployment by adapting Mastra's output to create an optimized version of your server. It extends the base Deployer class with Netlify-specific functionality. It enables you to run Mastra within Netlify serverless functions or edge functions.

Installation
Installation的直接链接

To use NetlifyDeployer, you need to install the @mastra/deployer-netlify package:

npm install @mastra/deployer-netlify@latest

Usage example
Usage example的直接链接

Import NetlifyDeployer and set it as the deployer in your Mastra configuration:

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

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

Constructor options
Constructor options的直接链接

  • target?: 'serverless' | 'edge': Deploy target for Netlify. Defaults to 'serverless'.
    • 'serverless': Standard Netlify Functions (Node.js runtime, 60s default timeout).
    • 'edge': Netlify Edge Functions (Deno-based runtime that runs at the edge closest to users without a fixed timeout).

Edge functions example
Edge functions example的直接链接

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',
}),
})

Output
Output的直接链接

After running mastra build, the deployer generates a .netlify folder. The build output includes all agents, tools, and workflows of your project, alongside a config.json file that configures the Netlify Frameworks API.

Serverless output (default)
Serverless output (default)的直接链接

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

The config.json file contains:

{
"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 output
Edge output的直接链接

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

The config.json file contains:

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