Skip to content

Commit c850030

Browse files
committed
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.
1 parent a907e2a commit c850030

9 files changed

Lines changed: 44 additions & 4 deletions

File tree

.changeset/big-geese-dream.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
"@trigger.dev/cli": patch
4+
---
5+
6+
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 = {

packages/trigger-sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"git-remote-origin-url": "^4.0.0",
3535
"git-repo-info": "^2.1.1",
3636
"node-fetch": "2.6.x",
37+
"proxy-agent": "^6.3.0",
3738
"slug": "^6.0.0",
3839
"terminal-link": "^3.0.0",
3940
"ulid": "^2.3.0",

packages/trigger-sdk/src/apiClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
urlWithSearchParams,
2727
} from "@trigger.dev/core";
2828

29-
import fetch, { type RequestInit } from "node-fetch";
29+
import fetch, { type RequestInit } from "./fetch";
3030
import { z } from "zod";
3131

3232
export type ApiClientOptions = {

packages/trigger-sdk/src/fetch.ts

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+
}

0 commit comments

Comments
 (0)