Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use zone_name for deployment of custom hostnames #4232

Merged

Conversation

romeupalos
Copy link
Contributor

Fixes #3662

What this PR solves / how to test:
use zone_name to determine a zone when the pattern is a custom hostname

In Cloudflare for SaaS, custom hostnames of third party domain owners can be used in Cloudflare.
Workers are allowed to intercept these requests based on the routes configuration.
Before this change, the same logic used by wrangler dev was used in wrangler deploy, which caused wrangler to fail with:

✘ [ERROR] Could not find zone for [partner-saas-domain.com]

Example of routes definition that wouldn't work before this PR:

routes = [
    { pattern = "buy.partner-saas-domain.com/*", zone_name = "mydomain.com" }
]

Author has included the following, where applicable:

Reviewer is to perform the following, as applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

@romeupalos romeupalos requested a review from a team as a code owner October 19, 2023 01:04
@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2023

🦋 Changeset detected

Latest commit: fe6c83c

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

This PR includes changesets to release 1 package
Name Type
wrangler Minor

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

@romeupalos
Copy link
Contributor Author

I have created a changeset for "minor", however, this change could also be considered a "patch".
Please, let me know if there is a need to change it.

@romeupalos
Copy link
Contributor Author

@penalosa Could you please take a look on this change when you have a chance?
This is impacting our companies production deployment. After every deploy, we need to add the triggers manually.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2023

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6644228754/npm-package-wrangler-4232

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6644228754/npm-package-wrangler-4232

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6644228754/npm-package-wrangler-4232 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6644228754/npm-package-cloudflare-pages-shared-4232

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.14.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare 3.20231016.0 3.20231016.0
workerd 1.20231016.0 1.20231016.0
workerd --version 1.20231016.0 2023-10-16

|

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Copy link
Contributor

Choose a reason for hiding this comment

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

@romeupalos thanks for this PR! Unfortunately I don't think this is the right fix for this issue, since we don't want to split the implementations of dev and deploy. I think a simpler option would be to change the implementation of getZoneForRoute to

export async function getZoneForRoute(route: Route): Promise<Zone | undefined> {
	const host = getHostFromRoute(route);
	let id: string | undefined;

	if (typeof route === "object" && "zone_id" in route) {
		id = route.zone_id;
	} else if (typeof route === "object" && "zone_name" in route) {
		id = await getZoneIdFromHost(route.zone_name);
	} else if (host) {
		id = await getZoneIdFromHost(host);
	}

	return id && host ? { id, host } : undefined;
}

Does that work for your use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@penalosa I've incorporated your code suggestion and updated the PR.
Please, let me know if it looks good to be merged.

@codecov
Copy link

codecov bot commented Oct 24, 2023

Codecov Report

Merging #4232 (fe6c83c) into main (980df04) will decrease coverage by 0.05%.
Report is 27 commits behind head on main.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4232      +/-   ##
==========================================
- Coverage   75.41%   75.37%   -0.05%     
==========================================
  Files         223      223              
  Lines       12231    12292      +61     
  Branches     3161     3177      +16     
==========================================
+ Hits         9224     9265      +41     
- Misses       3007     3027      +20     
Files Coverage Δ
packages/wrangler/src/zones.ts 73.97% <100.00%> (+1.75%) ⬆️

... and 19 files with indirect coverage changes

@romeupalos romeupalos force-pushed the romeupalos/3662-fix-saas-domains-deploy branch from b14af00 to 3378f99 Compare October 24, 2023 16:30
@@ -369,22 +369,6 @@ describe("wrangler dev", () => {
expect(std.err).toMatchInlineSnapshot(`""`);
});

it("should fail for non-existing zones", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@penalosa
I've removed this UT, since it does not seem to be correct when having Cloudflare for SaaS product in mind.
Please, let me know if it is ok to remove it.

@penalosa penalosa merged commit 69b4303 into cloudflare:main Oct 25, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Wrangler routes don't work with Cloudflare for SaaS Custom Hostnames
2 participants