Skip to content

Commit

Permalink
Merge 8ff5a9f into 954526f
Browse files Browse the repository at this point in the history
  • Loading branch information
imranolas committed Jan 21, 2015
2 parents 954526f + 8ff5a9f commit 9457db4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
37 changes: 28 additions & 9 deletions lib/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,42 @@ var _ = require("lodash");
* @param {Function} cb
*/
module.exports.plugin = function (bs, tunnelRunner, cb) {

var opts = {};
var options = bs.options;
var port = bs.options.port;
//var debug = bs.debug;

if (_.isString(options.tunnel)) {
opts.subdomain = options.tunnel;
if (_.isArray(options.tunnel)) {
var urls = [];
options.tunnel.forEach(function(subdomain) {
var opts = {
subdomain: subdomain
};

tunnelRunner(port, opts, function (err, tunnel) {
if (err) {
throw err;
}
urls.push(tunnel.url);
if (urls.length === options.tunnel.length) {
cb(urls.join("\n"), true);
}
});

});
} else {
if (_.isString(options.tunnel)) { opts.subdomain = options.tunnel; }

tunnelRunner(port, opts, function (err, tunnel) {
if (err) {
throw err;
}
cb(tunnel.url, true);
});
}


//debug("Trying tunnel connection with: %s ", options.tunnel || "no subdomain specified");

tunnelRunner(port, opts, function (err, tunnel) {
if (err) {
throw err;
}
cb(tunnel.url, true);
});

};
19 changes: 19 additions & 0 deletions test/specs/e2e/e2e.server.tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ describe("E2E server test with tunnel", function () {
done();
});
});
it("can create multiple tunnel connections with an array of sub domains", function (done) {
tunnel.plugin({
options: {
urls: {},
tunnel: [
"shane0987654321",
"imran0987654321"
],
port: _port
},
events: {}
}, require("localtunnel"), function (url, bool) {
assert.include(url, "shane0987654321");
assert.include(url, "imran0987654321");
assert.isTrue(bool);
done();
});
});

});

describe("Creating tunnels", function () {
Expand Down

0 comments on commit 9457db4

Please sign in to comment.