Cloudflare Pages
Cloudflare Pages hosting attaches to a JavaScript app that Aspire already models — it is not a standalone “point at a folder” resource. You add your frontend with the standard Aspire JavaScript APIs, then mark it for Pages.
Deploy a frontend to Pages
Section titled “Deploy a frontend to Pages”builder.AddViteApp("web", "../web") // or AddNodeApp / AddJavaScriptApp .PublishAsCloudflarePages();await builder.addViteApp('web', '../web').publishAsCloudflarePages();aspire run→ the app runs as its normal dev server (e.g. Vite).aspire deploy→ the app’s build runs, then the output is uploaded withwrangler pages deploy. The Pages project is created if it doesn’t exist.
Options
Section titled “Options”builder.AddViteApp("web", "../web") .PublishAsCloudflarePages(options => { options.ProjectName = "my-site"; // defaults to a sanitized resource name options.OutputDirectory = "dist"; // build output dir (Vite default) options.Branch = "main"; // production branch options.BuildCommand = "npm run build"; options.SkipBuild = false; // set true if the output is already built });await builder.addViteApp('web', '../web').publishAsCloudflarePages({ configure: async options => { await options.projectName.set('my-site'); await options.outputDirectory.set('dist'); await options.branch.set('main'); await options.buildCommand.set('npm run build'); await options.skipBuild.set(false); }});Talking to your API
Section titled “Talking to your API”Inject the API’s URL so the frontend can call it:
var api = builder.AddProject<Projects.Api>("api") .WithHttpEndpoint(name: "http") .PublishAsCloudflareContainer() .WithCustomDomain("api.example.com", "your-zone-id");
builder.AddViteApp("web", "../web") .WithEnvironment("VITE_API_URL", api.GetEndpoint("http")) .PublishAsCloudflarePages();const api = await builder.addProject('api', '../Api/Api.csproj') .withHttpEndpoint({ name: 'http' }) .publishAsCloudflareContainer() .withCustomDomain('api.example.com', 'your-zone-id');await builder.addViteApp('web', '../web') .withEnvironment('VITE_API_URL', api.getEndpoint('http')) .publishAsCloudflarePages();The build receives resolved WithEnvironment values in publish context. Endpoint references use the target’s custom domain (https://api.example.com here), not a local dev-server URL. A referenced endpoint must have a Cloudflare target and custom domain; otherwise provide its production URL explicitly. The default workers.dev placeholder is not an account-qualified production address.
In the frontend, read import.meta.env.VITE_API_URL and fetch from it. Configure the API’s CORS policy for the site’s origin.
Requirements
Section titled “Requirements”- wrangler installed — see How wrangler authenticates.
- API token with Cloudflare Pages: Edit — see API Tokens.
Custom domains
Section titled “Custom domains”var zone = builder.AddDeploymentParameter("zone-id");var host = builder.AddDeploymentParameter("web-hostname");
builder.AddViteApp("web", "../web") .PublishAsCloudflarePages() .WithCustomDomain(host, zone);const zone = await builder.addDeploymentParameter('zone-id');const host = await builder.addDeploymentParameter('web-hostname');await builder.addViteApp('web', '../web') .publishAsCloudflarePages() .withCustomDomainParameters(host, zone);Custom domains require DNS: Edit and Zone: Read on the relevant zone, and the Zone ID.
