NetlifyDeployer
The NetlifyDeployer deploys Mastra applications to Netlify Functions, handling site creation, configuration, and deployment processes. It extends the abstract Deployer class to provide Netlify-specific deployment functionality.
Usage Example
import { Mastra } from '@mastra/core';
import { NetlifyDeployer } from '@mastra/deployer-netlify';
const mastra = new Mastra({
deployer: new NetlifyDeployer({
scope: 'your-team-slug',
projectName: 'your-project-name',
token: 'your-netlify-token'
}),
// ... other Mastra configuration options
});
Parameters
Constructor Parameters
scope:
projectName:
token:
Environment Variables
The NetlifyDeployer handles environment variables from multiple sources:
- Environment Files: Variables from
.env.production
and.env
files. - Configuration: Variables passed through the Mastra configuration.
- Netlify Dashboard: Variables can also be managed through Netlify’s web interface.
Build Mastra Project
To build your Mastra project for Netlify deployment:
npx mastra build
The build process generates the following output structure in the .mastra/output
directory:
.mastra/output/
├── netlify/
│ └── functions/
│ └── api/
│ └── index.mjs # Application entry point
└── netlify.toml # Netlify configuration
Netlify Configuration
The NetlifyDeployer automatically generates a netlify.toml
configuration file in .mastra/output
with the following settings:
[functions]
node_bundler = "esbuild"
directory = "netlify/functions"
[[redirects]]
force = true
from = "/*"
status = 200
to = "/.netlify/functions/api/:splat"
Deployment Options
After building, you can deploy your Mastra application .mastra/output
to Netlify using any of these methods:
-
Netlify CLI: Deploy directly using Netlify’s official CLI tool
- Install the CLI:
npm install -g netlify-cli
- Navigate to the output directory:
cd .mastra/output
- Deploy with functions directory specified:
netlify deploy --dir . --functions ./netlify/functions
- For production deployment add
--prod
flag:netlify deploy --prod --dir . --functions ./netlify/functions
- Install the CLI:
-
Netlify Dashboard: Connect your Git repository or drag-and-drop the build output through the Netlify dashboard
-
Netlify Dev: Run your Mastra application locally with Netlify’s development environment
You can also run
netlify dev
in your output directory.mastra/output
to test your Mastra application locally.