Skip to content

Commit 7833db4

Browse files
feat: add proxy support to the CLI (triggerdotdev#404)
* feat: add proxy support for node-fetch This process is expected to allow the CLI and SDK to work in environments where proxy is enabled. * Revert "feat: add proxy support for node-fetch" This reverts commit c850030. * feat: add proxy support for node-fetch (CLI only) --------- Co-authored-by: Matt Aitken <matt@mattaitken.com>
1 parent 6de8bd4 commit 7833db4

6 files changed

Lines changed: 25 additions & 3 deletions

File tree

.changeset/big-geese-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli": patch
3+
---
4+
5+
feat: add proxy support for node-fetch

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"ora": "^6.1.2",
7777
"path-to-regexp": "^6.2.1",
7878
"posthog-node": "^3.1.1",
79+
"proxy-agent": "^6.3.0",
7980
"simple-git": "^3.19.0",
8081
"terminal-link": "^3.0.0",
8182
"tsconfck": "^2.1.2",

packages/cli/src/commands/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import childProcess from "child_process";
22
import chokidar from "chokidar";
33
import fs from "fs/promises";
44
import ngrok from "ngrok";
5-
import fetch from "node-fetch";
5+
import fetch from "../utils/fetchUseProxy";
66
import ora, { Ora } from "ora";
77
import pathModule from "path";
88
import util from "util";

packages/cli/src/utils/addDependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ora, { type Ora } from "ora";
44
import pathModule from "path";
55
import { getUserPackageManager, type PackageManager } from "./getUserPkgManager";
66
import fs from "fs/promises";
7-
import fetch from "node-fetch";
7+
import fetch from "./fetchUseProxy";
88
import { z } from "zod";
99

1010
export type InstallPackage = {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import node_fetch, { RequestInfo as _RequestInfo, RequestInit as _RequestInit } from "node-fetch";
2+
import { ProxyAgent } from "proxy-agent";
3+
4+
export type RequestInfo = _RequestInfo;
5+
export type RequestInit = _RequestInit;
6+
7+
export default function fetch(url: RequestInfo, init?: RequestInit) {
8+
const fetchInit: RequestInit = { ...init };
9+
10+
// If agent is not specified, specify proxy-agent and use environment variables such as HTTPS_PROXY.
11+
if (!fetchInit.agent) {
12+
fetchInit.agent = new ProxyAgent();
13+
}
14+
15+
return node_fetch(url, fetchInit);
16+
}

packages/cli/src/utils/triggerApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fetch from "node-fetch";
1+
import fetch from "./fetchUseProxy";
22
import { z } from "zod";
33

44
export type CreateEndpointOptions = {

0 commit comments

Comments
 (0)