Skip to content

feat: Add Proxy support for @powersync/node #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

feat: Add Proxy support for @powersync/node #573

wants to merge 10 commits into from

Conversation

Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Apr 18, 2025

Node package

Introduced support for specifying proxy environment variables for the connection methods. HTTP will use EnvHttpProxyAgent(see https://github.com/nodejs/undici/pull/2994/files#diff-e75b15c5fd859828aa0413c608603d1152bd54320aabd8ec8f73b023c924d0db) from undici and Websockets will use proxy-agent. In both cases the libraries automatically use the correct env variable. For HTTP this will typically be HTTP_PROXY or HTTPS_PROXY and for Websockets it will be WS_PROXY or WSS_PROXY, with other known options also available.

The HTTP dispatcher can be overridden with the dispatcher connect() option:

await db.connect(new DemoConnector(), {
    connectionMethod: SyncStreamConnectionMethod.HTTP,
    dispatcher: new MyAgent()
  });

Common package

To support specifying a custom option for the connect method of the Node package, I needed to ensure that config is passed along correctly.

Testing

Easiest way to test is to create a a session access token with another demo and use it in the node demo's connector.

MITM with custom CA

HTTPS_PROXY=http://localhost:8082/  # change to `https://localhost:8080/` to test https proxy protocol
SYNC_SERVICE=https://xxxxxx.powersync.staging.journeyapps.com/
SSL_CERT_FILE=somepath/ca-cert.pem  # pem from mitmproxy

Running:
Terminal 1

mitmproxy --set stream_large_bodies=0 --listen-port 8082

Terminal 2

node --use-openssl-ca --loader ts-node/esm -r dotenv/config src/main.ts

Copy link

changeset-bot bot commented Apr 18, 2025

🦋 Changeset detected

Latest commit: b2c0dcd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@powersync/node Minor
@powersync/common Minor
@powersync/op-sqlite Patch
@powersync/react-native Patch
@powersync/tanstack-react-query Patch
@powersync/web Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Chriztiaan Chriztiaan marked this pull request as ready for review April 23, 2025 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants