Skip to content

Commit e2508ce

Browse files
committed
Using EnvHttpProxyAgent for HTTP proxy to automatically pick up envs.
1 parent 9df3018 commit e2508ce

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

packages/node/src/sync/stream/NodeRemote.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@powersync/common';
1414
import { BSON } from 'bson';
1515
import Agent from 'proxy-agent';
16-
import { ProxyAgent } from 'undici';
16+
import { ProxyAgent, EnvHttpProxyAgent } from 'undici';
1717
import { WebSocket } from 'ws';
1818

1919
export const STREAMING_POST_TIMEOUT_MS = 30_000;
@@ -32,10 +32,8 @@ export class NodeRemote extends AbstractRemote {
3232
protected logger: ILogger = DEFAULT_REMOTE_LOGGER,
3333
options?: Partial<AbstractRemoteOptions>
3434
) {
35-
// Automatic env vars are not supported by undici
36-
// proxy-agent does not work directly with dispatcher
37-
const proxy = process.env.HTTPS_PROXY ?? process.env.HTTP_PROXY;
38-
const agent = proxy ? new ProxyAgent(proxy) : undefined;
35+
// Automatically uses relevant env vars for HTTP
36+
const agent = new EnvHttpProxyAgent();
3937

4038
super(connector, logger, {
4139
...(options ?? {}),
@@ -50,8 +48,7 @@ export class NodeRemote extends AbstractRemote {
5048

5149
protected createSocket(url: string): globalThis.WebSocket {
5250
return new WebSocket(url, {
53-
// Undici does not seem to be compatible with ws, using `proxy-agent` instead.
54-
// Automatically uses WS_PROXY or WSS_PROXY env vars
51+
// Automatically uses relevant env vars for web sockets
5552
agent: new Agent.ProxyAgent(),
5653
headers: {
5754
'User-Agent': this.getUserAgent()

0 commit comments

Comments
 (0)