Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (/^https/.test(urlObj.protocol)) {
options.addr = 'https://' + urlObj.hostname;
if (urlObj.port) {
options.addr += ':' + urlObj.port;
}
options.host_header = 'rewrite';
} else { // http:
var port = urlObj.port || 80;
options.addr = urlObj.hostname + ':' + port;
options.host_header = urlObj.hostname;
if (port !== 80) {
// include port in host header when not default port 80
options.host_header += ':' + port;
}
}
var connect = Promise.promisify(ngrok.connect);
return connect(options)
.then(tunnelUrl => {
var urlObj = url.parse(tunnelUrl);
console.log('Connected private encrypted tunnel to ' + host + ' (' + urlObj.host.split('.')[0] + ')');
return urlObj.host;
})
.catch(ex => {
if (tries < 2) {
// on error, wait and retry
return Promise.delay(1000).then(() =>
exports.connect(host, token, tries + 1)
);
}
throw ex;
});
};