@@ -5,121 +5,115 @@ Node library to enable opening Socket connections via an HTTPS proxy.
55Based on the implementation in https://github.com/TooTallNate/node-https-proxy-agent ,
66but adapted to expose raw Sockets, instead of just http/https requests.
77
8- ## Installation
8+ ### Note on tedious and mssql
9+ The useProxyForTedious has been removed, if you require this functionality please use v0.2.2.
910
10- yarn add @journeyapps/https-proxy-socket
11+ ## Installation
12+ ``` bash
13+ yarn add @journeyapps/https-proxy-socket
14+ npm install @journeyapps/https-proxy-socket
15+ pnpm add @journeyapps/https-proxy-socket
16+ ```
1117
1218## Usage - node-fetch
1319
14- import { HttpsProxySocket } from '@journeyapps/https-proxy-socket';
15- import fetch from 'node-fetch';
16-
17- /** Proxy connection options */
18- const proxy = new HttpsProxySocket('https://my-proxy.test', {
19- /** Proxy auth and headers may be set here, for example: */
20- auth: 'myuser:mypassword' // Basic auth
21- });
22-
23- const agent = proxy.agent({
24- /**
25- * Additional TLS options for the host may be set here, for example:
26- * rejectUnauthorized: false, // Disable TLS checks completely (dangerous)
27- * ca: fs.readFileSync('my-ca-cert.pem') // Use a custom CA cert
28- *
29- * Documentation of the available options is available here:
30- * https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
31- * https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
32- */
33- });
34-
35- const response = await fetch('https://myhost.test', { agent: agent });
20+ ``` javascript
21+ import { HttpsProxySocket } from ' @journeyapps/https-proxy-socket' ;
22+ import fetch from ' node-fetch' ;
23+
24+ /** Proxy connection options */
25+ const proxy = new HttpsProxySocket (' https://my-proxy.test' , {
26+ /** Proxy auth and headers may be set here, for example: */
27+ auth: ' myuser:mypassword' , // Basic auth
28+ });
29+
30+ const agent = proxy .agent ({
31+ /**
32+ * Additional TLS options for the host may be set here, for example:
33+ * rejectUnauthorized: false, // Disable TLS checks completely (dangerous)
34+ * ca: fs.readFileSync('my-ca-cert.pem') // Use a custom CA cert
35+ *
36+ * Documentation of the available options is available here:
37+ * https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
38+ * https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
39+ */
40+ });
41+
42+ const response = await fetch (' https://myhost.test' , { agent: agent });
43+ ```
3644
3745## Usage - Direct socket
3846
39- import { HttpsProxySocket } from '@journeyapps/https-proxy-socket';
40- const proxy = new HttpsProxySocket('https://my-proxy.test');
41-
42- const socket = await proxy.connect({host: 'myhost.test', port: 1234});
43-
44- ## Usage - mssql
45-
46- import sql from 'mssql'
47- import { HttpsProxySocket, useProxyForTedious } from '@journeyapps/https-proxy-socket';
48-
49- const proxy = new HttpsProxySocket({
50- /** Same as above */
51- });
52-
53- /** Register the proxy globally for tedious/mssql */
54- useProxyForTedious(proxy);
55-
56- async function run() {
57- /** Connect using the proxy */
58- await sql.connect('mssql://username:pwd@myserver.database.windows.net/mydb?encrypt=true')
59- try {
60- const result = await sql.query`Select TOP(1) * from mytable`
61- console.dir(result);
62- } finally {
63- await sql.close();
64- }
65- }
66-
67- run().catch(console.error);
47+ ``` javascript
48+ import { HttpsProxySocket } from ' @journeyapps/https-proxy-socket' ;
49+ const proxy = new HttpsProxySocket (' https://my-proxy.test' );
6850
51+ const socket = await proxy .connect ({ host: ' myhost.test' , port: 1234 });
52+ ```
6953
7054## Usage - MongoDB
55+
7156The socks package needs to be added to your package.json dependencies for this to work.
7257See the MongoDB documentation for details: https://www.mongodb.com/docs/drivers/node/current/security/socks/
7358
74- import * as mongo from 'mongodb';
75- import { useProxyForMongo } from '@journeyapps/https-proxy-socket';
76-
77- const SRV_URI = 'mongodb+srv://<username>:<password>@cluster0.jzuewet.mongodb.net';
78- const PROXY = 'us-cc-proxy.journeyapps.com'; // Or za-cc-proxy.journeyapps.com
79- const PROXY_PORT = 443
80-
81- /**
82- * Register the proxy globally for MongoDB
83- * This retuens a close function to end the socket
84- */
85- const { close } = useProxyForMongo({
86- proxy: PROXY,
87- auth: <egress_token> // See JourneyApps MongoDB Token section below
88- });
89-
90- async function run() {
91- const client = new mongo.MongoClient(SRV_URI, {
92- proxyPort: PROXY_PORT,
93- proxyHost: PROXY,
94- });
95- try {
96- const database = client.db('poc');
97- const data = database.collection('data');
98-
99- const results = await data.find({ index: { $lt: 5 } }).toArray();
100- console.log(results);
101- } finally {
102- close()
103- await client.close();
104- }
105- }
106-
107- run().catch(console.error);
59+ ``` javascript
60+
61+ import * as mongo from ' mongodb' ;
62+ import { useProxyForMongo } from ' @journeyapps/https-proxy-socket' ;
63+
64+ const SRV_URI = ' mongodb+srv://<username>:<password>@cluster0.jzuewet.mongodb.net' ;
65+ const PROXY = ' us-cc-proxy.journeyapps.com' ; // Or za-cc-proxy.journeyapps.com
66+ const PROXY_PORT = 443
67+
68+ /**
69+ * Register the proxy globally for MongoDB
70+ * This retuens a close function to end the socket
71+ */
72+ const { close } = useProxyForMongo ({
73+ proxy: PROXY ,
74+ auth: < egress_token> // See JourneyApps MongoDB Token section below
75+ });
76+
77+ async function run () {
78+ const client = new mongo.MongoClient (SRV_URI , {
79+ proxyPort: PROXY_PORT ,
80+ proxyHost: PROXY ,
81+ });
82+ try {
83+ const database = client .db (' poc' );
84+ const data = database .collection (' data' );
85+
86+ const results = await data .find ({ index: { $lt: 5 } }).toArray ();
87+ console .log (results);
88+ } finally {
89+ close ()
90+ await client .close ();
91+ }
92+ }
93+
94+ run ().catch (console .error );
95+ ```
96+
10897## JourneyApps MongoDB Token
109- Using Mongo Atlas usually means the connection is a SRV string. Under the hood Mongo driver converts this to a standard connection string.
98+
99+ Using Mongo Atlas usually means the connection is a SRV string. Under the hood Mongo driver converts this to a standard connection string.
110100When the driver opens socket connections it will have one for each replica set member. These connections will need to be allowed by the CloudCode egress proxy to work.
111101Prior contacting JourneyApps support, get your SRV string and run the following:
102+
112103``` bash
113104# your SRV is mongodb+srv://<username>:<password>@cluster1.vlnzcbp.mongodb.net
114105# You can run it with the included credentials
115106npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://your_username:your_password@cluster1.vlnzcbp.mongodb.net
116107# Or without
117108npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://cluster1.vlnzcbp.mongodb.net
118109```
110+
119111This will output the below to your console:
120- ``` js
112+
113+ ``` javascript
121114{
122- replicas: ' ac-mayaavr-shard-00-02.vlnzcbp.mongodb.net:27017,ac-mayaavr-shard-00-01.vlnzcbp.mongodb.net:27017,ac-mayaavr-shard-00-00.vlnzcbp.mongodb.net:27017'
115+ replicas: ' ac-mayaavr-shard-00-02.vlnzcbp.mongodb.net:27017,ac-mayaavr-shard-00-01.vlnzcbp.mongodb.net:27017,ac-mayaavr-shard-00-00.vlnzcbp.mongodb.net:27017' ;
123116}
124117```
125- When requesting the token from JourneyApps support, please provide the replicas string as well.
118+
119+ When requesting the token from JourneyApps support, please provide the replicas string as well.
0 commit comments