Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/Local.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Local(){
if(typeof options['onlyCommand'] !== 'undefined')
return;

const binaryPath = this.getBinaryPath();
const binaryPath = this.getBinaryPath(null, options['bs-host']);
that.binaryPath = binaryPath;
childProcess.exec('echo "" > ' + that.logfile);
that.opcode = 'start';
Expand Down Expand Up @@ -123,7 +123,7 @@ function Local(){
callback();
}
});
});
}, options['bs-host']);
};

this.isRunning = function(){
Expand Down Expand Up @@ -249,7 +249,7 @@ function Local(){
}
};

this.getBinaryPath = function(callback){
this.getBinaryPath = function(callback, bsHost){
if(typeof(this.binaryPath) == 'undefined'){
this.binary = new LocalBinary();
var conf = {};
Expand All @@ -261,9 +261,9 @@ function Local(){
conf.useCaCertificate = this.useCaCertificate;
}
if(!callback) {
return this.binary.binaryPath(conf, this.key, this.retriesLeft);
return this.binary.binaryPath(conf, bsHost, this.key, this.retriesLeft);
}
this.binary.binaryPath(conf, this.key, this.retriesLeft, callback);
this.binary.binaryPath(conf, bsHost, this.key, this.retriesLeft, callback);
} else {
console.log('BINARY PATH IS DEFINED');
if(!callback) {
Expand Down
5 changes: 3 additions & 2 deletions lib/LocalBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function LocalBinary(){

let cmd, opts;
cmd = 'node';
opts = [path.join(__dirname, 'fetchDownloadSourceUrl.js'), this.key];
opts = [path.join(__dirname, 'fetchDownloadSourceUrl.js'), this.key, this.bsHost];

if (retries == 4 || (process.env.BINARY_DOWNLOAD_FALLBACK_ENABLED == 'true' && this.parentRetries == 4)) {
opts.push(true, this.downloadErrorMessage || process.env.BINARY_DOWNLOAD_ERROR_MESSAGE);
Expand Down Expand Up @@ -230,8 +230,9 @@ function LocalBinary(){
});
};

this.binaryPath = function(conf, key, parentRetries, callback){
this.binaryPath = function(conf, bsHost, key, parentRetries, callback){
this.key = key;
this.bsHost = bsHost;
this.parentRetries = parentRetries;
var destParentDir = this.getAvailableDirs();
var destBinaryName = (this.windows) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal';
Expand Down
11 changes: 6 additions & 5 deletions lib/fetchDownloadSourceUrl.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const https = require('https'),
fs = require('fs'),
HttpsProxyAgent = require('https-proxy-agent');
HttpsProxyAgent = require('https-proxy-agent'),
{ isUndefined } = require('./util');

const authToken = process.argv[2], proxyHost = process.argv[5], proxyPort = process.argv[6], useCaCertificate = process.argv[7], downloadFallback = process.argv[3], downloadErrorMessage = process.argv[4];
const authToken = process.argv[2], bsHost = process.argv[3], proxyHost = process.argv[6], proxyPort = process.argv[7], useCaCertificate = process.argv[8], downloadFallback = process.argv[4], downloadErrorMessage = process.argv[5];

let body = '', data = {'auth_token': authToken};
const options = {
hostname: 'local.browserstack.com',
hostname: !isUndefined(bsHost) ? bsHost : 'local.browserstack.com',
port: 443,
path: '/binary/api/v1/endpoint',
method: 'POST',
Expand All @@ -20,13 +21,13 @@ if (downloadFallback == 'true') {
data['error_message'] = downloadErrorMessage;
}

if(proxyHost && proxyPort) {
if(!isUndefined(proxyHost) && !isUndefined(proxyPort)) {
options.agent = new HttpsProxyAgent({
host: proxyHost,
port: proxyPort
});
}
if (useCaCertificate) {
if (!isUndefined(useCaCertificate)) {
try {
options.ca = fs.readFileSync(useCaCertificate);
} catch(err) {
Expand Down
1 change: 1 addition & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.isUndefined = value => (value === undefined || value === null || value === 'undefined');
Loading