CustomDomain
Configure custom domain for a Cloudflare Worker using the Cloudflare Custom Domains API.
Props
The domain name to bind to the worker.const domain = await CustomDomain("api-domain", {
name: "api.example.com",
workerName: worker.name
});
Cloudflare Zone ID for the domain.
Inferred from the domain name
Name of the worker to bind to the domain.
environment
string
default:"production"
Worker environment (defaults to production).
If true, adopt an existing custom domain binding during creation.
Output
The unique identifier for the Cloudflare domain binding.
The domain name bound to the worker.
Name of the worker bound to this domain.
Cloudflare Zone ID for the domain.
Time at which the domain binding was created.
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"]
});