Skip to content

Commit 9df3018

Browse files
committed
Added minor documentation and typing.
1 parent 468dc58 commit 9df3018

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

.changeset/hip-lamps-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/node': minor
3+
---
4+
5+
Introduced support for specifying proxy environment variables for the connection methods. For HTTP it supports `HTTP_PROXY` or `HTTPS_PROXY`, and for WebSockets it supports `WS_PROXY` and `WSS_PROXY`.

.changeset/thick-lies-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/common': minor
3+
---
4+
5+
Added `fetchOptions` to AbstractRemoteOptions. Allows consumers to include fields such as `dispatcher` (e.g. for proxy support) to the fetch invocations.

packages/common/src/client/sync/stream/AbstractRemote.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ export type AbstractRemoteOptions = {
8686
*/
8787
fetchImplementation: FetchImplementation | FetchImplementationProvider;
8888

89-
// TODO
89+
/**
90+
* Optional options to pass directly to all `fetch` calls.
91+
*
92+
* This can include fields such as `dispatcher` (e.g. for proxy support),
93+
* `cache`, or any other fetch-compatible options.
94+
*/
9095
fetchOptions?: {};
9196
};
9297

packages/node/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ contains everything you need to know to get started implementing PowerSync in yo
5656

5757
A simple example using `@powersync/node` is available in the [`demos/example-node/`](../demos/example-node) directory.
5858

59+
# Proxy Support
60+
61+
This SDK supports HTTP, HTTPS, and WebSocket proxies via environment variables.
62+
63+
## HTTP Connection Method
64+
65+
Internally we probe the http environment variables and apply it to fetch requests ([undici](https://www.npmjs.com/package/undici/v/5.6.0))
66+
67+
- Set the `HTTPS_PROXY` or `HTTP_PROXY` environment variable to automatically route HTTP requests through a proxy.
68+
69+
## WEB Socket Connection Method
70+
71+
Internally the [proxy-agent](https://www.npmjs.com/package/proxy-agent) dependency for WebSocket proxies, which has its own internal code for automatically picking up the appropriate environment variables:
72+
73+
- Set the `WS_PROXY` or `WSS_PROXY` environment variable to route the webocket connections through a proxy.
74+
5975
# Found a bug or need help?
6076

6177
- Join our [Discord server](https://discord.gg/powersync) where you can browse topics from our community, ask questions, share feedback, or just say hello :)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ export class NodeRemote extends AbstractRemote {
5050

5151
protected createSocket(url: string): globalThis.WebSocket {
5252
return new WebSocket(url, {
53-
// Undici does not seem to be compatible with ws
53+
// Undici does not seem to be compatible with ws, using `proxy-agent` instead.
54+
// Automatically uses WS_PROXY or WSS_PROXY env vars
5455
agent: new Agent.ProxyAgent(),
5556
headers: {
5657
'User-Agent': this.getUserAgent()
5758
}
58-
}) as any as globalThis.WebSocket; // TODO
59+
}) as any as globalThis.WebSocket; // This is compatible in Node environments
5960
}
6061

6162
getUserAgent(): string {

0 commit comments

Comments
 (0)