Cloudflare Operations

Deploy static sites to Cloudflare Pages using the wrangler CLI.

Operations

Operation Description
Cloudflare.EnsureAuthenticated
Verify Cloudflare credentials. Prompts interactively if environment variables are not set. See authentication for setup.
Cloudflare.EnsureAuthenticated();
Cloudflare.PagesDeploy
Deploy the ./dist directory to Cloudflare Pages.
var frontend = Directory("./frontend");
Cloudflare.PagesDeploy(frontend, o => o.WithProjectName("my-site"));
Cloudflare.PagesDeploy(frontend, o => o
  .WithProjectName("my-site")
  .WithBranch("main"));
Cloudflare.PagesDeployDirectory
Deploy a specific output directory to Cloudflare Pages.
var frontend = Directory("./frontend");
Cloudflare.PagesDeployDirectory(frontend, "./dist", o => o.WithProjectName("my-site"));
Cloudflare.PagesDeployDirectory(frontend, "./build", o => o
  .WithProjectName("my-site")
  .WithBranch("preview"));
Cloudflare.PagesListProjects
List all Cloudflare Pages projects.
Cloudflare.PagesListProjects();
Cloudflare.PagesCreateProject
Create a new Cloudflare Pages project.
Cloudflare.PagesCreateProject("my-site");
Cloudflare.PagesCreateProject("my-site", "develop");
Cloudflare.PagesListDeployments
List deployments for a Cloudflare Pages project.
Cloudflare.PagesListDeployments("my-site");
Cloudflare.PagesListDeployments(); // Uses CLOUDFLARE_PROJECT_NAME env var

Authentication

Cloudflare operations require an API token and account ID. Set these as environment variables or enter them when prompted.

Environment Variables

Variable Description
CLOUDFLARE_API_TOKEN API token with Cloudflare Pages permissions
CLOUDFLARE_ACCOUNT_ID Your Cloudflare account ID (found in dashboard URL)
CLOUDFLARE_PROJECT_NAME Optional default project name for Pages operations

Interactive Prompting

When running locally without environment variables set, Cloudflare.EnsureAuthenticated() will prompt for credentials interactively. The API token input is hidden for security. Credentials are only stored for the current build session and are cleared when the process exits.

Creating a Cloudflare API Token

  1. Go to Cloudflare Dashboard → Profile → API Tokens
  2. Click Create Token
  3. Select Edit Cloudflare Workers template (includes Pages permissions)
  4. Under Account Resources, select your account
  5. Under Zone Resources, select All zones or specific zones
  6. Click Continue to summary, then Create Token
  7. Copy the token and set it as CLOUDFLARE_API_TOKEN

Finding Your Account ID

Your account ID is in the Cloudflare dashboard URL: https://dash.cloudflare.com/ACCOUNT_ID/...
Or find it on any zone's overview page in the right sidebar under API → Account ID.

Example

Deploy a static site to Cloudflare Pages.

build.ando
// Ensure we're authenticated with Cloudflare
Cloudflare.EnsureAuthenticated();

// Build the site
Npm.InDirectory("./website").Ci();
Npm.InDirectory("./website").Run("build");

// Deploy to Cloudflare Pages
Cloudflare.InDirectory("./website").PagesDeploy(o => o
  .WithProjectName("my-website")
  .WithBranch("main"));