@mastra/deployer-cloudflare
v0.14.24
Published
A Cloudflare Workers deployer for Mastra applications.
Maintainers
Keywords
Readme
@mastra/deployer-cloudflare
A Cloudflare Workers deployer for Mastra applications.
Features
- Deploy Mastra applications to Cloudflare Workers
- Configure custom domains and routes
- Support for worker namespaces
- Automatic environment variable configuration
Installation
pnpm add @mastra/deployer-cloudflareUsage
The Cloudflare deployer is used as part of the Mastra framework:
import { Mastra } from '@mastra/core';
import { CloudflareDeployer } from '@mastra/deployer-cloudflare';
const 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',
},
});
const mastra = new Mastra({
deployer,
// ... other Mastra configuration options
});Configuration
Constructor Options
scope(required): Your Cloudflare account IDprojectName: Name of your worker projectroutes: Array of route configurations for your workerpattern: URL pattern to matchzone_name: Domain zone namecustom_domain: Whether to use a custom domain
workerNamespace: Namespace for your workerauth: Cloudflare authentication detailsapiToken: Your Cloudflare API tokenapiEmail: Your Cloudflare account email
Environment Variables
The deployer will automatically load environment variables from:
.envfiles in your project- Environment variables passed through the Mastra configuration
Routes
Routes can be configured to direct traffic to your worker based on URL patterns and domains:
const routes = [
{
pattern: 'api.example.com/*',
zone_name: 'example.com',
custom_domain: true,
},
{
pattern: 'example.com/api/*',
zone_name: 'example.com',
},
];Each route requires:
pattern: URL pattern to matchzone_name: Domain zone namecustom_domain: (optional) Set to true to use a custom domain
Requirements
- Cloudflare account with Workers enabled
- API token with appropriate permissions
- Domain(s) configured in Cloudflare (for custom domains)
