Skip to content

Commit 06e206d

Browse files
author
EspressoTrip-v2
committed
readme update
1 parent a6a0ae5 commit 06e206d

1 file changed

Lines changed: 47 additions & 21 deletions

File tree

README.md

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,52 @@ but adapted to expose raw Sockets, instead of just http/https requests.
1111

1212
## Usage - node-fetch
1313

14-
const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
15-
const fetch = require('node-fetch');
14+
import { HttpsProxySocket } from '@journeyapps/https-proxy-socket';
15+
import fetch from 'node-fetch';
1616

17-
// Proxy connection options
17+
/** Proxy connection options */
1818
const proxy = new HttpsProxySocket('https://my-proxy.test', {
19-
// Proxy auth and headers may be set here, for example:
19+
/** Proxy auth and headers may be set here, for example: */
2020
auth: 'myuser:mypassword' // Basic auth
2121
});
2222

2323
const agent = proxy.agent({
24-
// Additional TLS options for the host may be set here, for example:
25-
// rejectUnauthorized: false, // Disable TLS checks completely (dangerous)
26-
// ca: fs.readFileSync('my-ca-cert.pem') // Use a custom CA cert
27-
28-
// Documentation of the available options is available here:
29-
// https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
30-
// https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
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+
30+
/**
31+
* Documentation of the available options is available here:
32+
* https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
33+
* https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
34+
*/
3135
});
3236

3337
const response = await fetch('https://myhost.test', { agent: agent });
3438

3539
## Usage - Direct socket
3640

37-
const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
41+
import { HttpsProxySocket } from '@journeyapps/https-proxy-socket';
3842
const proxy = new HttpsProxySocket('https://my-proxy.test');
3943

4044
const socket = await proxy.connect({host: 'myhost.test', port: 1234});
4145

4246
## Usage - mssql
4347

44-
const sql = require('mssql')
45-
const { HttpsProxySocket, useProxyForTedious } = require('@journeyapps/https-proxy-socket');
48+
import sql from 'mssql'
49+
import { HttpsProxySocket, useProxyForTedious } from '@journeyapps/https-proxy-socket';
4650

4751
const proxy = new HttpsProxySocket({
48-
// Same as above
52+
/** Same as above */
4953
});
5054

51-
// Register the proxy globally for tedious/mssql
55+
/** Register the proxy globally for tedious/mssql */
5256
useProxyForTedious(proxy);
5357

5458
async function run() {
55-
// Connect using the proxy
59+
/** Connect using the proxy */
5660
await sql.connect('mssql://username:pwd@myserver.database.windows.net/mydb?encrypt=true')
5761
try {
5862
const result = await sql.query`Select TOP(1) * from mytable`
@@ -76,10 +80,13 @@ See the MongoDB documentation for details: https://www.mongodb.com/docs/drivers/
7680
const PROXY = 'us-cc-proxy.journeyapps.com'; // Or za-cc-proxy.journeyapps.com
7781
const PROXY_PORT = 443
7882

79-
// Register the proxy globally for MongoDB
80-
useProxyForMongo({
83+
/**
84+
* Register the proxy globally for MongoDB
85+
* This retuens a close function to end the socket
86+
*/
87+
const { close } = useProxyForMongo({
8188
proxy: PROXY,
82-
auth: <egress_token>
89+
auth: <egress_token> // See JourneyApps MongoDB Token section below
8390
});
8491

8592
async function run() {
@@ -94,8 +101,27 @@ See the MongoDB documentation for details: https://www.mongodb.com/docs/drivers/
94101
const results = await data.find({ index: { $lt: 5 } }).toArray();
95102
console.log(results);
96103
} finally {
97-
await client.close();
104+
close()
105+
await client.close();
98106
}
99107
}
100108

101109
run().catch(console.error);
110+
## JourneyApps MongoDB Token
111+
Using the Mongo Atlas usually means the connection is a SRV string. Under the hood Mongo driver converts this to a standard connection string.
112+
When 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.
113+
Prior contacting JourneyApps support, get your SRV string and run the following:
114+
```bash
115+
# your SRV is mongodb+srv://<username>:<password>@cluster1.vlnzcbp.mongodb.net
116+
# You can run it with the included credentials
117+
npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://your_username:your_password@cluster1.vlnzcbp.mongodb.net
118+
# Or without
119+
npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://cluster1.vlnzcbp.mongodb.net
120+
```
121+
This will output the below to your console:
122+
```js
123+
{
124+
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'
125+
}
126+
```
127+
When requesting the token from JourneyApps support, please provide the replicas string as well.

0 commit comments

Comments
 (0)