Skip to content

Commit 410f7cd

Browse files
committed
change ngrok with localtunnel
1 parent 6e66c5a commit 410f7cd

File tree

3 files changed

+135
-104
lines changed

3 files changed

+135
-104
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"body-parser": "^1.15.2",
3131
"eventemitter3": "^2.0.2",
3232
"express": "^4.14.0",
33-
"morgan": "^1.7.0",
34-
"ngrok": "^2.2.6"
33+
"localtunnel": "^1.8.2",
34+
"morgan": "^1.7.0"
3535
},
3636
"devDependencies": {
3737
"ava": "^0.18.1",

src/webhook.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from 'express'
22
import bodyParser from 'body-parser'
33
import morgan from 'morgan'
4-
import ngrok from 'ngrok'
4+
import localtunnel from 'localtunnel'
55

66
import crypto from 'crypto'
77

@@ -16,6 +16,10 @@ class Webhook {
1616
this.callback = callback
1717
this.events = 0
1818

19+
this._parseBody = this._parseBody.bind(this)
20+
this._getSignature = this._getSignature.bind(this)
21+
this._createTunnel = this._createTunnel.bind(this)
22+
1923
const app = express()
2024
const APP_PORT = opts.port || DEFAULT_PORT
2125
const APP_ENDPOINT = opts.endpoint || DEFAULT_ENDPOINT
@@ -41,16 +45,25 @@ class Webhook {
4145
this._webserver.listen(APP_PORT, (err) => {
4246
if (!err) {
4347
whCallback(APP_PORT)
44-
if (APP_NGROK) ngrok.connect(APP_PORT, (err, url) => {
45-
if (err) return
46-
console.log(`Created ngrok tunnel at ${url}`)
47-
})
48+
if (APP_NGROK) {
49+
this._createTunnel(APP_PORT)
50+
}
4851
}
4952
}).on('error', (err) => {
5053
console.error(err)
5154
})
5255
}
5356

57+
_createTunnel (port) {
58+
const tunnel = localtunnel(port, (err, {url}) => {
59+
if (err) {
60+
return console.log(`Failed to create tunnel. error: `, err)
61+
}
62+
console.log(`Tunnel created successfully at ${url}`)
63+
})
64+
this.tunnel = tunnel
65+
}
66+
5467
_parseBody (req, res, next) {
5568
const events = req.body && req.body.events
5669
if (events) {

0 commit comments

Comments
 (0)