Skip to content
This repository has been archived by the owner on Oct 10, 2021. It is now read-only.

Commit

Permalink
refactor: function for local url building
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Oct 1, 2017
1 parent 542b122 commit 4c5d666
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/setup.js
Expand Up @@ -66,16 +66,21 @@ function setup_test_instance(opt, cb) {
bouncer.on('request', on_request(proxy.web));
bouncer.on('upgrade', on_request(proxy.ws));

function local_url (port, path) {
var base = 'http://' + loopback + ':' + port;
return path ? base + path : base;
}

function on_request(bounce) {
return function(req, res) {
var args = [].slice.call(arguments);
if (is_control_req(req)) {
args.push({ target: 'http://' + loopback + ':' + control_port });
args.push({ target: local_url(control_port) });
bounce.apply(proxy, args);
return;
}

args.push({ target: 'http://' + loopback + ':' + support_port }, on_support_server_proxy_done);
args.push({ target: local_url(support_port) }, on_support_server_proxy_done);
bounce.apply(proxy, args);
};
}
Expand Down Expand Up @@ -105,7 +110,7 @@ function setup_test_instance(opt, cb) {
debug('bouncer active on port %d', app_port);

if (!tunnel) {
return cb(null, 'http://' + loopback + ':' + app_port + '/__zuul');
return cb(null, local_url(app_port, '/__zuul'));
}

tunnel.connect(app_port, cb);
Expand Down

0 comments on commit 4c5d666

Please sign in to comment.