Deploy a Worker behind a custom domain

deploy & domains

// what it does

Attaches a custom domain so the entire hostname routes to the Worker, with Cloudflare provisioning the DNS record and TLS automatically. Use it when the Worker itself is the API or site at that hostname, with no origin behind it. The zone must already be on your Cloudflare account.

// shell

$ wrangler deploy --domain api.example.com

// gotcha

A custom domain manages its own DNS record, so it conflicts with any existing record for that hostname and can't coexist with a plain route on the same exact hostname.