Skip to main content

CustomDomain

Configure custom domain for a Cloudflare Worker using the Cloudflare Custom Domains API.

Props

name
string
required
The domain name to bind to the worker.
const domain = await CustomDomain("api-domain", {
  name: "api.example.com",
  workerName: worker.name
});
zoneId
string
Cloudflare Zone ID for the domain.
workerName
string
required
Name of the worker to bind to the domain.
environment
string
default:"production"
Worker environment (defaults to production).
adopt
boolean
default:"false"
If true, adopt an existing custom domain binding during creation.

Output

id
string
The unique identifier for the Cloudflare domain binding.
name
string
The domain name bound to the worker.
workerName
string
Name of the worker bound to this domain.
zoneId
string
Cloudflare Zone ID for the domain.
environment
string
Worker environment.
createdAt
number
Time at which the domain binding was created.
updatedAt
number
Time at which the domain binding was last updated.

Examples

Basic Custom Domain

const worker = await Worker("api", {
  name: "my-api-worker",
  entrypoint: "./src/api-worker.ts"
});

const domain = await CustomDomain("api-domain", {
  name: "api.example.com",
  workerName: worker.name
});

Custom Domain with Zone ID

const domain = await CustomDomain("api-domain", {
  name: "api.example.com",
  zoneId: "YOUR_ZONE_ID",
  workerName: "my-api-worker"
});

Adopt Existing Domain

const domain = await CustomDomain("api-domain", {
  name: "api.example.com",
  workerName: "my-api-worker",
  adopt: true
});

Custom Domain with Worker Domains Prop

const worker = await Worker("api", {
  entrypoint: "./src/api.ts",
  domains: ["api.example.com"]
});

Build docs developers (and LLMs) love