Skip to content

Instantly share code, notes, and snippets.

@gippy
Created April 30, 2018 12:30
Show Gist options
  • Save gippy/dfbee59d868edc0d074e81bb112f5bef to your computer and use it in GitHub Desktop.
Save gippy/dfbee59d868edc0d074e81bb112f5bef to your computer and use it in GitHub Desktop.
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