Skip to content

Proxy Support - #2831

Merged
blittle merged 7 commits into
mainfrom
bl-proxy-support
Apr 3, 2025
Merged

blittle merged 7 commits into
mainfrom
bl-proxy-support

Conversation

@blittle

@blittle blittle commented Apr 1, 2025 •

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Add support for HTTP proxies with the environment variables SHOPIFY_HTTP_PROXY and SHOPIFY_HTTPS_PROXY. Define one of these variables before starting the Hydrogen dev server to make all requests go through a proxy serve

SHOPIFY_HTTP_PROXY=http://localhost:8888 shopify hydrogen dev

WHAT is this pull request doing?

When starting the hydrogen server for local development, we boot the app in workerd. This allows us to execute code in an actual worker environment, mostly identical to production. Proxy support in workerd itself is not easy to configure, nor do they do not implement ProxyAgent.

Instead of relying on workerd to proxy network requests, utilize outboundService in miniflare to execute all network requests in a node environment. Then from that environment we utilize undici with a ProxyAgent. We already use outboundService for when NODE_TLS_REJECT_UNAUTHORIZED=0.

The only downsides to this approach our version of undici's fetch might slightly deviate from workerd's implementation. So there's a small chance that something that works locally, won't work in prod, or vice-versa. Also, this appears difficult to write an automated test to protect against future regressions .

HOW to test your changes?

  1. Setup a local proxy, like through https://www.charlesproxy.com/
  2. Startup your dev server passing in the address to the proxy: SHOPIFY_HTTP_PROXY=http://localhost:8888 shopify hydrogen dev
  3. Verify all requests go through the proxy.
  4. If you really want to validate things, also download Little Snitch to block all requests directly going to Shopify not through the proxy.

Post-merge steps

  1. We need to ship a new version of Hydrogen, and then a new version of the CLI.
  2. We need to figure out where to document SHOPIFY_HTTP_PROXY.

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@shopify

shopify Bot commented Apr 1, 2025 •

Copy link
Copy Markdown
Contributor

Oxygen deployed a preview of your bl-proxy-support branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment April 3, 2025 7:24 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment April 3, 2025 7:24 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment April 3, 2025 7:24 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment April 3, 2025 7:24 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment April 3, 2025 7:24 PM

Learn more about Hydrogen's GitHub integration.

Comment on lines -240 to -241
// https://github.com/cloudflare/workers-sdk/issues/5345
response.headers.delete('Content-Encoding');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This issue does not appear to be a problem anymore.

const useOutboundService =
isNormalWorker &&
(process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0' ||
process.env.SHOPIFY_HTTP_PROXY ||

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.

same suggestion about explicit checks here (and line 347)

@blittle
blittle force-pushed the bl-proxy-support branch from d8b85c6 to 954c254 Compare April 1, 2025 18:10
@blittle

blittle commented Apr 1, 2025

Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions

github-actions Bot commented Apr 1, 2025

Copy link
Copy Markdown
Contributor

🫰✨ Thanks @blittle! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20250401182347",
"@shopify/hydrogen": "0.0.0-snapshot-20250401182347",
"@shopify/mini-oxygen": "0.0.0-snapshot-20250401182347"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

@blittle
blittle force-pushed the bl-proxy-support branch from efb1195 to 0bf3e21 Compare April 3, 2025 19:16
@blittle
blittle merged commit 92b3d0c into main Apr 3, 2025
@blittle
blittle deleted the bl-proxy-support branch April 3, 2025 19:29
juanpprieto pushed a commit that referenced this pull request Sep 17, 2025
* Add support for SHOPIFY_HTTP_PROXY for the hydrogen dev server

* Add changeset

* Change upgrade command to use nodekit fetch

* Don't make proxy requests to localhost

* Update changeset

* Fix

* Fix formatting
frandiox pushed a commit that referenced this pull request Jun 16, 2026
* Add support for SHOPIFY_HTTP_PROXY for the hydrogen dev server

* Add changeset

* Change upgrade command to use nodekit fetch

* Don't make proxy requests to localhost

* Update changeset

* Fix

* Fix formatting
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.

2 participants