Skip to content

Commit

Permalink
Have tail use proxy for websocket connection (#4149)
Browse files Browse the repository at this point in the history
  • Loading branch information
jspspike committed Oct 27, 2023
1 parent 0453b44 commit 7e05f38
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-files-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fixed issue with `tail` not using proxy
1 change: 1 addition & 0 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"@cloudflare/pages-shared": "workspace:^",
"@cloudflare/types": "^6.18.4",
"@cloudflare/workers-tsconfig": "workspace:*",
"https-proxy-agent": "7.0.2",
"@cloudflare/workers-types": "^4.20230914.0",
"@iarna/toml": "^3.0.0",
"@microsoft/api-extractor": "^7.28.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const fgGreenColor = "\x1b[32m";
export const DEFAULT_LOCAL_PORT = 8787;
export const DEFAULT_INSPECTOR_PORT = 9229;

const proxy =
export const proxy =
process.env.https_proxy ||
process.env.HTTPS_PROXY ||
process.env.http_proxy ||
Expand Down
8 changes: 8 additions & 0 deletions packages/wrangler/src/tail/createTail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { HttpsProxyAgent } from "https-proxy-agent";
import WebSocket from "ws";
import { version as packageVersion } from "../../package.json";
import { fetchResult } from "../cfetch";
import { proxy } from "../index";
import type { TailFilterMessage, Outcome } from "./filters";
export type { TailCLIFilters } from "./filters";
export { translateCLICommandToFilterMessage } from "./filters";
Expand Down Expand Up @@ -100,11 +102,14 @@ export async function createPagesTail({
{ method: "DELETE" }
);

const p = proxy ? { agent: new HttpsProxyAgent(proxy) } : {};

const tail = new WebSocket(tailRecord.url, TRACE_VERSION, {
headers: {
"Sec-WebSocket-Protocol": TRACE_VERSION, // needs to be `trace-v1` to be accepted
"User-Agent": `wrangler-js/${packageVersion}`,
},
...p,
});

// send filters when we open up
Expand Down Expand Up @@ -165,12 +170,15 @@ export async function createTail(
await fetchResult(deleteUrl, { method: "DELETE" });
}

const p = proxy ? { agent: new HttpsProxyAgent(proxy) } : {};

// connect to the tail
const tail = new WebSocket(websocketUrl, TRACE_VERSION, {
headers: {
"Sec-WebSocket-Protocol": TRACE_VERSION, // needs to be `trace-v1` to be accepted
"User-Agent": `wrangler-js/${packageVersion}`,
},
...p,
});

// send filters when we open up
Expand Down
33 changes: 18 additions & 15 deletions pnpm-lock.yaml

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

0 comments on commit 7e05f38

Please sign in to comment.