-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlocal-tunnel.js
45 lines (39 loc) · 985 Bytes
/
local-tunnel.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
41
42
43
44
45
var localtunnel = require('localtunnel'),
_ = require('lodash');
function startTunneling(data) {
var params = _getParamsAsObject(data);
var tunnel = localtunnel(params.port, {
subdomain: params.subdomain
}, function(err, tunnel) {
if (err) {
console.log("Error while creating localtunnel", err);
process.send({
type: 'process:msg',
error: err.message
});
} else {
console.log("success", tunnel.url);
process.send({
type: 'process:msg',
data: tunnel
});
}
});
tunnel.on('close', function() {
console.log("closing tunnel..");
});
process.on('uncaughtException', function() {
process.exit(1);
});
}
function _getParamsAsObject(data) {
var parameters = [];
while (data.length) parameters.push(data.splice(0, 2));
return _.fromPairs(parameters);
}
if (!module.parent) {
startTunneling(process.argv.splice(2));
}
module.exports = {
startTunneling: startTunneling
};