docs/src/content/en/guides/deployment/cloudflare.mdx
import Steps from "@site/src/components/Steps"; import StepItem from "@site/src/components/StepItem";
Use @mastra/deployer-cloudflare to deploy your Mastra server to Cloudflare Workers. The deployer bundles your code and generates a wrangler.jsonc file conforming to Cloudflare's wrangler configuration, ready to deploy with no additional configuration.
:::info
If you're using a server adapter or web framework, deploy the way you normally would for that framework.
:::
You'll need a Mastra application and a Cloudflare account.
:::warning Cloudflare Workers use an ephemeral filesystem, so any storage you configure (including observability storage) must be hosted externally. If you're using LibSQLStore with a file URL, switch to a remotely hosted database. :::
Add the @mastra/deployer-cloudflare package to your project:
npm install @mastra/deployer-cloudflare@latest
Import CloudflareDeployer and set it as the deployer in your Mastra configuration:
import { Mastra } from '@mastra/core'
// highlight-next-line
import { CloudflareDeployer } from '@mastra/deployer-cloudflare'
export const mastra = new Mastra({
// highlight-start
deployer: new CloudflareDeployer({
name: 'your-project-name',
vars: {
NODE_ENV: 'production',
},
}),
// highlight-end
})
In order to test your Cloudflare Worker locally, also install the wrangler CLI:
npm install -D wrangler
After setting up your project, push it to your remote Git provider of choice (e.g. GitHub).
<Steps> <StepItem> Connect your repository to Cloudflare. On the "Workers & Pages" dashboard, select **Create application** and choose your Git provider in the next step. Continue with the setup process and select the repository you want to deploy.:::note
Remember to set your environment variables needed to run your application (e.g. your [model provider](/models/providers) API key). You can upload secrets from your `.env` file using `npx wrangler secret bulk .env`. See [Secrets](/reference/deployer/cloudflare#secrets) for details.
:::
Since the [Mastra server](/docs/server/mastra-server) prefixes every API endpoint with `/api`, you have to add it to your URLs when making requests.
:::note
Set up [authentication](/docs/server/auth) before exposing your endpoints publicly.
:::