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 correct host in exchange #2651

Merged
merged 2 commits into from
Feb 17, 2023
Merged

Use correct host in exchange #2651

merged 2 commits into from
Feb 17, 2023

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Jan 30, 2023

What this PR solves / how to test:

URLs from the Cloudflare API are usually relative to the zone. Sometimes the base zone will be grey-clouded, and so the host must be swapped out for the worker route host, which is more likely to be orange-clouded.

Associated docs issues/PR:

  • Bugfix, so no docs changes needed

Author has included the following, where applicable:

  • Tests
  • Changeset

Reviewer has performed the following, where 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

Fixes #2018, #2602, #2581

@penalosa penalosa requested a review from a team as a code owner January 30, 2023 20:32
@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2023

🦋 Changeset detected

Latest commit: 1ebf435

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 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/runs/4205879066/npm-package-wrangler-2651

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

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2651/npm-package-wrangler-2651

Or you can use npx with this latest build directly:

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

@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Merging #2651 (1ebf435) into main (de0cb57) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2651      +/-   ##
==========================================
- Coverage   68.16%   68.12%   -0.05%     
==========================================
  Files         166      166              
  Lines       10155    10161       +6     
  Branches     2703     2705       +2     
==========================================
  Hits         6922     6922              
- Misses       3233     3239       +6     
Impacted Files Coverage Δ
packages/wrangler/src/create-worker-preview.ts 8.97% <0.00%> (-0.75%) ⬇️

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

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

It is looking good! Just a question around the nullish operator issue and suggestion on handling exchange_url

packages/wrangler/src/create-worker-preview.ts Outdated Show resolved Hide resolved
host,
inspectorUrl: new URL(`${inspector_websocket}?${query}`),
prewarmUrl: new URL(prewarm),
host: ctx.host ?? inspector.host,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the host be "" (I don't remember if the config validator prevents that) if so this could have unintended behavior.

// the worker route host, which is more likely to be orange-clouded
function switchHost(originalUrl: string, host?: string): URL {
const url = new URL(originalUrl);
url.hostname = host ?? url.hostname;
Copy link
Contributor

Choose a reason for hiding this comment

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

If host can be falsey "" this could cause unintended behaviors

Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason not to always just use the probably-orange-clouded host?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes we might not be able to parse an orange-clouded host (i.e. when the only route is */*)

Copy link
Member

Choose a reason for hiding this comment

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

So is there a circumstance when I'm using a wildcard route e.g. */* but my apex domain is grey-clouded, where this won't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but there's kinda nothing we can do there if you've provided no other information. I think there's a dev.host config parameter you can add to explicitly set this, but I'll double check

@penalosa penalosa force-pushed the penalosa/use-host-in-exchange branch from 9be7694 to c735ceb Compare February 16, 2023 17:33
Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

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

My concern was discussed offline. Looks good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants