Skip to content

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);

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.

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.
  • 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.