Skip to content

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
@Chriztiaan Chriztiaan merged commit f40ecf9 into main Apr 24, 2025
7 checks passed
@Chriztiaan Chriztiaan deleted the proxy branch April 24, 2025 07:17
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