-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
40 lines (30 loc) · 782 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var ngrok = require('ngrok');
var xtend = require('xtend');
var AUTH_TOKEN = process.env.NGROK_AUTH_TOKEN;
function Tunnel(config) {
if (!this instanceof Tunnel) {
return new Tunnel(config);
}
var self = this;
self.tunnel_settings = config.tunnel;
if (AUTH_TOKEN) {
self.tunnel_settings.authtoken = AUTH_TOKEN;
}
}
Tunnel.prototype.connect = function(port, cb) {
var self = this;
ngrok.connect(xtend({ port: port }, self.tunnel_settings), function(err, url) {
if (err) {
err.stack = '';
cb(err);
return;
}
self.ngrok_url = url;
cb(null, url.replace('tcp://', 'http://') + '/__zuul');
});
};
Tunnel.prototype.close = function() {
var self = this;
ngrok.disconnect(self.ngrok_url);
};
module.exports = Tunnel;