fix(wrangler): don't proxy localhost requests during dev#12516
fix(wrangler): don't proxy localhost requests during dev#12516edmundhung merged 2 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 88594ca 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 |
|
Claude finished @edmundhung's task —— View job Changeset ReviewReviewing changeset file(s) for this PR...
✅ All changesets look good The changeset
The changeset effectively communicates what was broken, how it's fixed, and important details about the new behavior. |
d54a982 to
e3adbd1
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
Does this mean that proxy environment variables now work, or just that they don't crash? |
It should work. Just skip the proxy when a request is made against localhost. |
Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>
720903f to
88594ca
Compare
Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>
Fixes #8906.
It looks like wrangler's proxy setup bleeds into miniflare's inspector proxy and should skip proxying requests to localhost. I considered scoping the proxy setup to the wrangler CLI only , but the Vite plugin also needs it for remote binding API calls.
This fix replaces
ProxyAgentwith undici'sEnvHttpProxyAgent, which natively supportsNO_PROXY. WhenNO_PROXYis not set, it defaults tolocalhost,127.0.0.1,::1, so local dev server requests are never proxied.The
NO_PROXYconfig only applies to the request destination, not the proxy server address. So a proxy running on localhost (e.g.,HTTP_PROXY=http://127.0.0.1:11451) still works for outbound API calls.vite devwith a non existentHTTP_PROXY(e.g.http_proxy=http://127.0.0.1:11451 vite dev)TypeError: fetch failed)A picture of a cute animal (not mandatory, but encouraged)