Skip to content

Commit

Permalink
feat: implement proxy support (#1051)
Browse files Browse the repository at this point in the history
* feat: implement proxy support


prefer lower-case http proxy env vars

* Create calm-oranges-walk.md

update calm-oranges-walk.md

* chore: bump undici to get bug fix for http_proxy

* fix: default fetch to application/json unless otherwise provided

* Revert "fix: default fetch to application/json unless otherwise provided"

This reverts commit 338759b.

* chore: bump undici
  • Loading branch information
rozenmd authored May 24, 2022
1 parent 81d4ab3 commit 7e2e97b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/calm-oranges-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

feat: add support for using wrangler behind a proxy

Configures the undici library (the library wrangler uses for `fetch`) to send all requests via a proxy selected from the first non-empty environment variable from "https_proxy", "HTTPS_PROXY", "http_proxy" and "HTTP_PROXY".
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"timeago.js": "^4.0.2",
"tmp-promise": "^3.0.3",
"ts-dedent": "^2.2.0",
"undici": "^4.15.1",
"undici": "^5.3.0",
"update-check": "^1.5.4",
"ws": "^8.5.0",
"yargs": "^17.4.1"
Expand Down
12 changes: 12 additions & 0 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { render } from "ink";
import React from "react";
import onExit from "signal-exit";
import supportsColor from "supports-color";
import { setGlobalDispatcher, ProxyAgent } from "undici";
import makeCLI from "yargs";
import { version as wranglerVersion } from "../package.json";
import { fetchResult } from "./cfetch";
Expand Down Expand Up @@ -78,6 +79,17 @@ const resetColor = "\x1b[0m";
const fgGreenColor = "\x1b[32m";
const DEFAULT_LOCAL_PORT = 8787;

const proxy =
process.env.https_proxy ||
process.env.HTTPS_PROXY ||
process.env.http_proxy ||
process.env.HTTP_PROXY ||
undefined;

if (proxy) {
setGlobalDispatcher(new ProxyAgent(proxy));
}

function getRules(config: Config): Config["rules"] {
const rules = config.rules ?? config.build?.upload?.rules ?? [];

Expand Down

0 comments on commit 7e2e97b

Please sign in to comment.