#How to deploy Convex to produciton using Cloudflare Workers
5 messages · Page 1 of 1 (latest)
Hi @north pendant. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To deploy Convex to production using Cloudflare Workers (specifically Cloudflare Pages), you need to follow a series of steps to configure your project and environment. Here’s a summary based on the available knowledge sources:
1. Connect Your Git Repository to Cloudflare Pages
- Log in to your Cloudflare account and go to Pages.
- Click Create a Project and select your Git provider and repository.
- For the build command, use:
Set the build output directory tonpx @cloudflare/next-on-pages@1.vercel/output/static. - Add any required environment variables for both Production and Preview environments.
- Click Save and Deploy.
Note: Unlike Vercel, you do not override the build command with
npx convex deployfor Cloudflare Pages in this setup. The build command is specific to your framework (e.g., Next.js) and Cloudflare’s requirements, not Convex’s CLI deploy command at this step Setting Up Cloudflare Pages for Convex Preview Deployments.
2. Create the wrangler.toml Configuration File
- In your project root, create a
wrangler.tomlfile with the following content:
Replacename = "name-of-the-project" compatibility_flags = ["nodejs_compat_v2"] main = ".worker-next/index.mjs" assets = { directory = ".worker-next/assets", binding = "ASSETS" }"name-of-the-project"with your project’s name Step 3: Create the _worker.js Configuration File.
3. Enable Node.js Compatibility
- In your Cloudflare Pages project settings, under Bindings, add the
nodejs_compat_v2(ornodejs_compat) flag in the Compatibility flags section. This ensures Node.js compatibility for your deployment Step 5: Enable Node.js Compatibility.
4. Test Your Deployment
- Push a new branch to your repository.
- Cloudflare Pages will automatically build and deploy the branch.
- Visit the preview URL provided in the Cloudflare Pages dashboard to verify your changes Step 6: Test Your Deployment.
Important Notes:
- The knowledge sources do not provide a step-by-step guide for running
npx convex deployas part of the Cloudflare Pages build process, unlike Vercel or Netlify. The deployment process for Convex functions may need to be handled separately, or you may need to adapt your workflow if you want to automate Convex backend deployments alongside your frontend. - If you need to use Convex’s CLI for deploying backend functions, refer to the Convex CLI documentation for details on how to use
npx convex deployin CI/CD environments.
If you need more specific integration between Convex and Cloudflare Workers (not Pages), the knowledge sources do not provide explicit instructions. For advanced or custom setups, you may need to consult Convex support or community channels.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@north pendant Kapa.ai is still learning and improving, please let me know how I did by reacting below.