Custom Domains
Attach a custom hostname to a Container or Pages app with WithCustomDomain. Call it after PublishAsCloudflareContainer / PublishAsCloudflarePages.
Both the hostname and the Zone ID are deploy-specific configuration, so pass them as Aspire parameters rather than hard-coding them:
using AvantiPoint.Aspire.Hosting.Extensions;
var zone = builder.AddDeploymentParameter("zone-id");var apiHost = builder.AddDeploymentParameter("api-hostname");var webHost = builder.AddDeploymentParameter("web-hostname");
var api = builder.AddProject<Projects.Api>("api") .PublishAsCloudflareContainer() .WithCustomDomain(apiHost, zone);
builder.AddViteApp("web", "../web") .PublishAsCloudflarePages() .WithCustomDomain(webHost, zone);const zone = await builder.addDeploymentParameter('zone-id');const apiHost = await builder.addDeploymentParameter('api-hostname');const webHost = await builder.addDeploymentParameter('web-hostname');const api = await builder.addProject('api', '../Api/Api.csproj') .publishAsCloudflareContainer() .withCustomDomainParameters(apiHost, zone);await builder.addViteApp('web', '../web') .publishAsCloudflarePages() .withCustomDomainParameters(webHost, zone);Literal overloads — WithCustomDomain("api.example.com", "<zone-id>") — also exist for quick samples, and you can mix (parameter hostname + literal zone, or vice versa). Prefer parameters for real deployments.
WithCustomDomain is repeatable — call it multiple times to attach multiple hostnames.
What happens at deploy
Section titled “What happens at deploy”| Resource | Behavior |
|---|---|
| Container / Worker | A Workers custom domain is attached. Cloudflare creates the DNS record and issues the SSL certificate automatically. |
| Pages | The hostname is added to the Pages project and a proxied CNAME to <project>.pages.dev is upserted in the zone. |
Requirements
Section titled “Requirements”- The Zone ID for the domain.
- API token permissions DNS: Edit and Zone: Read on that zone — see API Tokens. The integration automatically requires these scopes once you use
WithCustomDomain.
