Created
April 30, 2018 12:30
-
-
Save gippy/dfbee59d868edc0d074e81bb112f5bef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createTunnel, closeTunnel } = require('proxy-chain'); | |
// This is how connection strings usually look like | |
const serviceConnectionString = '<protocol>://<auth>@<service-hostname>:<service port>'; | |
// Create tunnel for the service, this call will start local tunnel and | |
// return string in format localhost:<selected-free-port> which is address | |
// of the local tunnel. | |
const tunnelInfo = await createTunnel( | |
'http://<username>:<password>@<proxy-server-hostname>:<proxy-server-port>', | |
'<service-hostname>:<service-port>' | |
); | |
// We will reformat the connection string to use the tunnel instead of real hostname | |
const tunneledServiceConnectionString = serviceConnectionString.replace('<service-hostname>:<service-port>', tunnelInfo); | |
// Connect to any kind of client that uses connection strings | |
client.connect(tunneledServiceConnectionString); | |
// do something with the client... | |
// Close the tunnel when we are done | |
closeTunnel(tunnelInfo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment