How to deploy to Cloudflare Pages programmatically?
I'm making a website builder that allows users to deploy their website to cloudflare pages as
https://<uuid>.<website-builder>.com
. How do I go about this?
Do I use the Cloudflare Create Project API endpoint (https://developers.cloudflare.com/api/python/resources/pages/) to do this? If so, how do I upload the code into to the project?Cloudflare API | Pages
Interact with Cloudflare's products and services via the Cloudflare API
1 Reply
You can use the API endpoints to create a new project but I don't think you can upload the build directory that way. It would probably best to use a ci/cd environment such as GitHub actions and upload the assets using wrangler within the ci/cd. This guide touches on some of the basics: https://developers.cloudflare.com/pages/how-to/use-direct-upload-with-continuous-integration/
Cloudflare Docs
Use Direct Upload with continuous integration · Cloudflare Pages docs
Cloudflare Pages supports directly uploading prebuilt assets, allowing you to use custom build steps for your applications and deploy to Pages with Wrangler. This guide will teach you how to deploy your application to Pages, using continuous integration.