11import express from 'express'
22import bodyParser from 'body-parser'
33import morgan from 'morgan'
4- import ngrok from 'ngrok '
4+ import localtunnel from 'localtunnel '
55
66import 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