Tenant Routing
Custom Domain Kit captures tenantId during setup, but runtime traffic should be mapped by hostname in your own product.
Store the Mapping
When a domain is created or a webhook is received, store:
| Field | Use |
|---|---|
hostname | Lookup key for incoming requests. |
tenantId | Customer account, workspace, project, or organization. |
domainId | Custom Domain Kit domain ID for API operations. |
status | Whether the domain is ready for traffic. |
Read the Host
At runtime, resolve tenant by host:
const host =
request.headers.get("x-cdk-original-host") ??
request.headers.get("x-forwarded-host") ??
request.headers.get("host");
const tenant = await findTenantByCustomHostname(host);Do Not Expect Tenant ID on Requests
Do not expect Custom Domain Kit to append tenantId to query strings, cookies, headers, or paths. The setup flow and webhooks carry tenantId; runtime requests should use your own hostname lookup.
Preserve Host
Most SaaS apps should keep Preserve Host disabled. Enable it only if your origin expects each customer hostname in the Host header and has routing and TLS behavior ready for those hostnames.
Redirects
If your origin emits absolute redirects, keep redirect rewriting enabled so customers stay on their custom hostname after login or navigation.
