Cloudflare Quickstart
This ties the pieces together: an R2 bucket, a .NET API that uses it, and a JavaScript frontend on Pages.
1. Set your credentials
Section titled “1. Set your credentials”For local aspire run against the MinIO emulator (.RunAsEmulator()), nothing is required. For deploying (or running against real R2), set:
export CLOUDFLARE_API_TOKEN="<your scoped token>"export CLOUDFLARE_ACCOUNT_ID="<your account id>"# only if your app accesses real R2 at runtime:export R2_ACCESS_KEY_ID="<r2 access key id>"export R2_SECRET_ACCESS_KEY="<r2 secret access key>"In development, prefer user-secrets on the AppHost over exporting secrets in your shell.
2. Install packages and wire up the AppHost
Section titled “2. Install packages and wire up the AppHost”Use an Aspire 13.6 CLI and an SDK supporting the net10.0 target. Install matching available AvantiPoint 13.6 packages from your package feed. Replace the package-version placeholder with that available version.
export AVANTIPOINT_VERSION="<available-13.6-package-version>"dotnet add AppHost/AppHost.csproj package AvantiPoint.Aspire.Hosting.Cloudflare --version "$AVANTIPOINT_VERSION"dotnet add AppHost/AppHost.csproj package AvantiPoint.Aspire.Hosting.Cloudflare.R2 --version "$AVANTIPOINT_VERSION"dotnet add AppHost/AppHost.csproj package AvantiPoint.Aspire.Hosting.Cloudflare.Pages --version "$AVANTIPOINT_VERSION"dotnet add AppHost/AppHost.csproj package AvantiPoint.Aspire.Hosting.Extensions --version "$AVANTIPOINT_VERSION"dotnet add AppHost/AppHost.csproj package Aspire.Hosting.JavaScript --version 13.6.0dotnet add AppHost/AppHost.csproj reference Api/Api.csprojProjects.Api is generated from the AppHost’s API project reference.
Create aspire.config.json alongside apphost.mts:
{ "appHost": { "path": "apphost.mts", "language": "typescript/nodejs" }, "sdk": { "version": "13.6.0" }, "packages": { "Aspire.Hosting.JavaScript": "13.6.0", "AvantiPoint.Aspire.Hosting.Cloudflare": "<available-13.6-package-version>", "AvantiPoint.Aspire.Hosting.Cloudflare.R2": "<available-13.6-package-version>", "AvantiPoint.Aspire.Hosting.Cloudflare.Pages": "<available-13.6-package-version>", "AvantiPoint.Aspire.Hosting.Extensions": "<available-13.6-package-version>" }}npm init -ynpm install vscode-jsonrpc@8.2.1npm install --save-dev typescript@6.0.3 tsx@4.23.15 @types/node@24.0.0aspire restoreThe CLI generates .aspire/modules/aspire.mts; use its .mjs import path from apphost.mts. The checked-in TypeScript sample demonstrates local project references and interop validation.
Adjust project paths to your solution. The Vite project at ../web must contain a build script and have its npm dependencies installed. In either AppHost language, the API remains a .NET service.
using Aspire.Hosting;using Aspire.Hosting.JavaScript;using AvantiPoint.Aspire.Hosting.Extensions;using AvantiPoint.Aspire.Hosting.Cloudflare;using AvantiPoint.Aspire.Hosting.Cloudflare.Pages;using AvantiPoint.Aspire.Hosting.Cloudflare.R2;
var builder = DistributedApplication.CreateBuilder(args);
// The Cloudflare deploy environment. Reads CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID.// Resources below resolve it automatically — no need to pass it around.builder.AddCloudflareEnvironment();
// Domains and the Zone ID are deploy-time config, not source — supply them as parameters.var zone = builder.AddDeploymentParameter("zone-id");var apiHost = builder.AddDeploymentParameter("api-hostname");var webHost = builder.AddDeploymentParameter("web-hostname");
// An R2 bucket. RunAsEmulator() → local MinIO during `aspire run`; deploy always uses real R2.var uploads = builder.AddR2Bucket("uploads").RunAsEmulator();
// A .NET API that reads/writes the bucket (becomes a Cloudflare Container on deploy).var api = builder.AddProject<Projects.Api>("api") .WithHttpEndpoint(name: "http") .WithReference(uploads) .PublishAsCloudflareContainer() .WithCustomDomain(apiHost, zone);
// A Vite frontend deployed to Cloudflare Pages.builder.AddViteApp("web", "../web") .WithEnvironment("VITE_API_URL", api.GetEndpoint("http")) .PublishAsCloudflarePages() .WithCustomDomain(webHost, zone);
builder.Build().Run();import { createBuilder } from './.aspire/modules/aspire.mjs';const builder = await createBuilder();await builder.addCloudflareEnvironment();const zone = await builder.addDeploymentParameter('zone-id');const apiHost = await builder.addDeploymentParameter('api-hostname');const webHost = await builder.addDeploymentParameter('web-hostname');const uploads = await builder.addR2Bucket('uploads').runAsEmulator();const api = await builder.addProject('api', '../Api/Api.csproj') .withHttpEndpoint({ name: 'http' }) .withReference(uploads) .publishAsCloudflareContainer() .withCustomDomainParameters(apiHost, zone);await builder.addViteApp('web', '../web') .withEnvironment('VITE_API_URL', api.getEndpoint('http')) .publishAsCloudflarePages() .withCustomDomainParameters(webHost, zone);await builder.build().run();3. Consume R2 in your .NET service (C#)
Section titled “3. Consume R2 in your .NET service (C#)”In the API (or any service) project:
dotnet add Api/Api.csproj package AvantiPoint.Aspire.Cloudflare.R2 --version "<available-13.6-package-version>"using AvantiPoint.Aspire.Cloudflare.R2;
builder.AddR2Client("uploads"); // registers IR2Client (and IAmazonS3) configured for R2// IR2Client is bound to the bucket — no bucket name to pass around.app.MapGet("/data", async (IR2Client r2) =>{ var obj = await r2.GetObjectAsync("data.json"); return Results.Stream(obj.ResponseStream, "application/json");});4. Run locally
Section titled “4. Run locally”aspire runBecause the bucket uses .RunAsEmulator(), MinIO starts, the bucket is created in it, and your services run against it — no Cloudflare credentials needed.
5. Deploy to Cloudflare
Section titled “5. Deploy to Cloudflare”aspire deployThe token is checked for activeness, R2 buckets are provisioned, the API container and Pages site are deployed via wrangler, and any custom domains are configured.
Provisioning / seeding
Section titled “Provisioning / seeding”Need to populate data before things start (migrations, seed files)? Add a console project that uses AddR2Client, and mark it as a local provisioning step that the others wait on:
var seeder = builder.AddProject<Projects.Seeder>("seeder") .WithReference(uploads) .WaitFor(uploads) .ExcludeFromManifest(); // runs locally; never deployed to Cloudflare
api.WaitForCompletion(seeder);const seeder = await builder.addProject('seeder', '../Seeder/Seeder.csproj') .withReference(uploads) .waitFor(uploads) .excludeFromManifest();await api.waitForCompletion(seeder);