Setup tunnel using localtunnel

This commit is contained in:
Brandon Keepers 2017-04-08 16:52:53 -05:00
parent f3073ca8b2
commit 3805b0d4bf
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
1 changed files with 29 additions and 0 deletions

View File

@ -17,6 +17,7 @@ program
process.exit(1);
}
}, process.env.PRIVATE_KEY)
.option('-t, --tunnel <subdomain>', 'Expose your local bot to the internet', process.env.NODE_ENV != 'production')
.parse(process.argv);
if(!program.integration) {
@ -36,6 +37,34 @@ if(!program.privateKey) {
}
}
if(program.tunnel) {
try {
setupTunnel();
} catch(err) {
console.warn('Run `npm install --save-dev localtunnel` to enable localtunnel.');
}
}
function setupTunnel() {
const localtunnel = require('localtunnel');
const subdomain = typeof program.tunnel == 'string' ?
program.tunnel :
require('os').userInfo().username;
const tunnel = localtunnel(program.port, {subdomain}, function (err, tunnel) {
if (err) {
console.warn('Could not open tunnel: ', err.message);
} else {
console.log('Listening on ' + tunnel.url);
tunnel.url;
}
});
tunnel.on('close', function() {
console.warn('Local tunnel closed');
});
}
const pkgConf = require('pkg-conf');
const resolve = require('resolve').sync;
const createProbot = require('../');