Skip to content

[wrangler] Add enabled and previews_enabled options for custom domains#13222

Open
maxwellpeterson wants to merge 3 commits intocloudflare:mainfrom
maxwellpeterson:mpeterson/custom-domain-preview-production-settings
Open

[wrangler] Add enabled and previews_enabled options for custom domains#13222
maxwellpeterson wants to merge 3 commits intocloudflare:mainfrom
maxwellpeterson:mpeterson/custom-domain-preview-production-settings

Conversation

@maxwellpeterson
Copy link
Copy Markdown
Member

@maxwellpeterson maxwellpeterson commented Apr 1, 2026

Fixes IAC-402

Add support for configuring enabled and previews_enabled on custom domain routes, allowing users to control whether a custom domain serves production and/or preview traffic. These optional boolean fields can be set on any route with custom_domain: true and are passed through to the custom domains API during deploy. When omitted, the API defaults to production-only for backwards compatibility. Users must explicitly opt-in to preview routing by setting previews_enabled: true.

Examples

Production-only

The default when both enabled and previews_enabled are omitted. Only requests to example.com will be routed to the Worker.

{ "pattern": "example.com", "custom_domain": true }
// OR
{ "pattern": "example.com", "custom_domain": true, "enabled": true }
// OR
{ "pattern": "example.com", "custom_domain": true, "previews_enabled": false }
// OR
{ "pattern": "example.com", "custom_domain": true, "enabled": true, "previews_enabled": false }

Previews-only

Requests to example.com will not be routed to the Worker. Requests to subdomains of example.com (e.g. my-feature.example.com) will be routed to the corresponding preview if one exists.

{ "pattern": "example.com", "custom_domain": true, "enabled": false, "previews_enabled": true }

Production and previews

Requests to example.com will be routed to the Worker. Requests to subdomains of example.com (e.g. my-feature.example.com) will be routed to the corresponding preview if one exists.

{ "pattern": "example.com", "custom_domain": true, "previews_enabled": true }
// OR
{ "pattern": "example.com", "custom_domain": true, "enabled": true, "previews_enabled": true }

Invalid (API returns validation error)

At least one of production or previews must be enabled.

{ "pattern": "example.com", "custom_domain": true, "enabled": false }
// OR
{ "pattern": "example.com", "custom_domain": true, "enabled": false, "previews_enabled": false }
image
  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s): None
    • Documentation not necessary because: This feature is in private beta and not available to the general public yet.

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

🦋 Changeset detected

Latest commit: 55ea49b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 1, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13222

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13222

miniflare

npm i https://pkg.pr.new/miniflare@13222

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13222

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13222

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13222

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13222

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13222

wrangler

npm i https://pkg.pr.new/wrangler@13222

commit: 55ea49b

…stom domains

Add support for configuring production_enabled and previews_enabled
on custom domain routes, allowing users to control whether a custom
domain serves production and/or preview traffic.

These optional boolean fields can be set on any route with
custom_domain: true and are passed through to the custom domains API
origins payload during deploy.
@maxwellpeterson maxwellpeterson force-pushed the mpeterson/custom-domain-preview-production-settings branch from 0760be1 to b44d762 Compare April 1, 2026 21:16
@maxwellpeterson maxwellpeterson marked this pull request as ready for review April 1, 2026 21:45
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team April 1, 2026 21:45
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/workers-utils/src/config/environment.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/construct-wrangler-config.ts: [@cloudflare/wrangler]
  • packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/helpers.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/routes.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deploy/deploy.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/utils/download-worker-config.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

The refactored isValidRouteValue logic accepted { pattern, zone_id,
zone_name } because both keys were recognized and the count matched.
Add an explicit mutual exclusion check to restore the previous behavior
where this combination was correctly rejected.
Copy link
Copy Markdown
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code itself is fine, but I have some questions/suggestions about the config shape cc @korinne

custom_domain?: boolean;
};
export type CustomDomainRoute = { pattern: string; custom_domain: boolean };
export type CustomDomainRoute = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is putting this in the custom domain route type set in stone? Long term I think something like the following would be clearer and would get away from locking us in to these config shapes just because we've previously had them:

routes: [{
  type: "preview",
  pattern: "*.example.com"
},{
  type: "custom_domain",
  pattern: "example.com"
}]

In the meantime, what about:

routes: [{
  preview: true,
  pattern: "*.example.com"
},{
  custom_domain: true,
  pattern: "example.com"
}]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previews are only supported for custom domains. I don't really see us adding them to regular routes in the future, since routes can already contain wildcards and there isn't a clear domain hierarchy to differentiate previews.

It's a little confusing to me to have separate "types" for custom_domain and previews, when they are actually the exact same thing at the API level. @1000hz has proposed a simplified domains API that would lend itself to this config shape:

{
  "domains": ["app.example.com", "my-app.cloudflare.app"],
  "preview_domains": ["previews.example.com", "my-app.cloudflare.app"]
{

which feels a lot simpler since users don't need to be aware of the different underlying route types. Regardless, do we want to make this config shape change now?

As-is adopting previews for existing users is as simple as adding "previews_enabled": true to their domain config. The wildcard syntax would be a Wrangler-only construct and isn't something users would be familiar with from any other touchpoint (dash, API, Terraform, etc.). The only place you would see it is in the actual DNS record that is created, which we're trying to abstract over here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@penalosa I definitely think we should change the domains config when we release the new config shape, but could we wait until then?

And yes I think just an array of domains like what @1000hz suggests is ideal

@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Apr 2, 2026
The API field was renamed from production_enabled to enabled. Update
all type definitions, validation, config mapping, deploy logic, and
tests to match.
@maxwellpeterson maxwellpeterson changed the title [wrangler] Add production_enabled and previews_enabled options for custom domains [wrangler] Add enabled and previews_enabled options for custom domains Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

4 participants