fix: Improve log messages for localtunnel (#349)

This commit is contained in:
Brandon Keepers 2017-11-25 22:03:31 -06:00 committed by GitHub
parent a1831021ec
commit b5d05b3913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 16 deletions

View File

@ -26,19 +26,6 @@ if (!program.privateKey) {
program.privateKey = findPrivateKey()
}
if (program.tunnel && !process.env.DISABLE_TUNNEL) {
try {
const setupTunnel = require('../lib/tunnel')
setupTunnel(program.tunnel, program.port).then(tunnel => {
console.log('Listening on ' + tunnel.url)
}).catch(err => {
console.warn('Could not open tunnel: ', err.message)
})
} catch (err) {
console.warn('Run `npm install --save-dev localtunnel` to enable localtunnel.')
}
}
const createProbot = require('../')
const probot = createProbot({
@ -49,6 +36,15 @@ const probot = createProbot({
webhookPath: program.webhookPath
})
if (program.tunnel && !process.env.DISABLE_TUNNEL) {
try {
const setupTunnel = require('../lib/tunnel')
setupTunnel(program.tunnel, program.port)
} catch (err) {
probot.logger.debug('Run `npm install --save-dev localtunnel` to enable localtunnel.')
}
}
pkgConf('probot').then(pkg => {
probot.setup(program.args.concat(pkg.apps || pkg.plugins || []))
probot.start()

View File

@ -1,5 +1,6 @@
const https = require('https')
const localtunnel = require('localtunnel')
const logger = require('./logger')
module.exports = function setupTunnel (subdomain, port, retries = 0) {
if (typeof subdomain !== 'string') {
@ -11,12 +12,16 @@ module.exports = function setupTunnel (subdomain, port, retries = 0) {
if (err) {
reject(err)
} else {
testTunnel(subdomain).then(() => resolve(tunnel)).catch(() => {
testTunnel(subdomain).then(() => {
logger.info('Listening on ' + tunnel.url)
resolve(tunnel)
}).catch((err) => {
if (retries < 3) {
console.warn(`Failed to connect to localtunnel.me. Trying again (tries: ${retries + 1})`)
logger.warn(`Could not connect to localtunnel.me. Trying again (tries: ${retries + 1})`)
resolve(setupTunnel(subdomain, port, retries + 1))
} else {
reject(new Error('Failed to connect to localtunnel.me. Giving up.'))
logger.warn(err, 'Failed to connect to localtunnel.me.')
reject(err)
}
})
}