Skip to content

Commit 3eeca3f

Browse files
Merge pull request #162 from browserstack/download_source_from_specified_host
Request download source from specified host
2 parents 3b190ed + 17a583a commit 3eeca3f

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

lib/Local.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function Local(){
3535
if(typeof options['onlyCommand'] !== 'undefined')
3636
return;
3737

38-
const binaryPath = this.getBinaryPath();
38+
const binaryPath = this.getBinaryPath(null, options['bs-host']);
3939
that.binaryPath = binaryPath;
4040
childProcess.exec('echo "" > ' + that.logfile);
4141
that.opcode = 'start';
@@ -123,7 +123,7 @@ function Local(){
123123
callback();
124124
}
125125
});
126-
});
126+
}, options['bs-host']);
127127
};
128128

129129
this.isRunning = function(){
@@ -249,7 +249,7 @@ function Local(){
249249
}
250250
};
251251

252-
this.getBinaryPath = function(callback){
252+
this.getBinaryPath = function(callback, bsHost){
253253
if(typeof(this.binaryPath) == 'undefined'){
254254
this.binary = new LocalBinary();
255255
var conf = {};
@@ -261,9 +261,9 @@ function Local(){
261261
conf.useCaCertificate = this.useCaCertificate;
262262
}
263263
if(!callback) {
264-
return this.binary.binaryPath(conf, this.key, this.retriesLeft);
264+
return this.binary.binaryPath(conf, bsHost, this.key, this.retriesLeft);
265265
}
266-
this.binary.binaryPath(conf, this.key, this.retriesLeft, callback);
266+
this.binary.binaryPath(conf, bsHost, this.key, this.retriesLeft, callback);
267267
} else {
268268
console.log('BINARY PATH IS DEFINED');
269269
if(!callback) {

lib/LocalBinary.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function LocalBinary(){
3232

3333
let cmd, opts;
3434
cmd = 'node';
35-
opts = [path.join(__dirname, 'fetchDownloadSourceUrl.js'), this.key];
35+
opts = [path.join(__dirname, 'fetchDownloadSourceUrl.js'), this.key, this.bsHost];
3636

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

233-
this.binaryPath = function(conf, key, parentRetries, callback){
233+
this.binaryPath = function(conf, bsHost, key, parentRetries, callback){
234234
this.key = key;
235+
this.bsHost = bsHost;
235236
this.parentRetries = parentRetries;
236237
var destParentDir = this.getAvailableDirs();
237238
var destBinaryName = (this.windows) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal';

lib/fetchDownloadSourceUrl.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const https = require('https'),
22
fs = require('fs'),
3-
HttpsProxyAgent = require('https-proxy-agent');
3+
HttpsProxyAgent = require('https-proxy-agent'),
4+
{ isUndefined } = require('./util');
45

5-
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];
6+
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];
67

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

23-
if(proxyHost && proxyPort) {
24+
if(!isUndefined(proxyHost) && !isUndefined(proxyPort)) {
2425
options.agent = new HttpsProxyAgent({
2526
host: proxyHost,
2627
port: proxyPort
2728
});
2829
}
29-
if (useCaCertificate) {
30+
if (!isUndefined(useCaCertificate)) {
3031
try {
3132
options.ca = fs.readFileSync(useCaCertificate);
3233
} catch(err) {

lib/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports.isUndefined = value => (value === undefined || value === null || value === 'undefined');

0 commit comments

Comments
 (0)