From aaa3992a78be4da0d04314dc724004c9af1d8247 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Sun, 8 Jan 2017 00:43:01 +0300 Subject: [PATCH] [webhook] Fix referencing options Bug: The confusion between using 'options' (passed by caller) and 'this.options' (cached on the object), we were making the assumption 'options.https' is unchanged! It's references is changed already as we had earlier assigned 'this.options' to point to 'options', thus same object. --- src/telegramWebHook.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/telegramWebHook.js b/src/telegramWebHook.js index 05bd1c2..e99d3e9 100644 --- a/src/telegramWebHook.js +++ b/src/telegramWebHook.js @@ -31,16 +31,16 @@ class TelegramBotWebHook { this._requestListener = this._requestListener.bind(this); this._parseBody = this._parseBody.bind(this); - if (options.key && options.cert) { + if (this.options.key && this.options.cert) { debug('HTTPS WebHook enabled (by key/cert)'); - this.options.https.key = fs.readFileSync(options.key); - this.options.https.cert = fs.readFileSync(options.cert); + this.options.https.key = fs.readFileSync(this.options.key); + this.options.https.cert = fs.readFileSync(this.options.cert); this._webServer = https.createServer(this.options.https, this._requestListener); - } else if (options.pfx) { + } else if (this.options.pfx) { debug('HTTPS WebHook enabled (by pfx)'); - this.options.https.pfx = fs.readFileSync(options.pfx); + this.options.https.pfx = fs.readFileSync(this.options.pfx); this._webServer = https.createServer(this.options.https, this._requestListener); - } else if (options.https) { + } else if (Object.keys(this.options.https).length) { debug('HTTPS WebHook enabled by (https)'); this._webServer = https.createServer(this.options.https, this._requestListener); } else { @@ -48,8 +48,8 @@ class TelegramBotWebHook { this._webServer = http.createServer(this._requestListener); } - this._webServer.listen(options.port, options.host, () => { - debug('WebHook listening on port %s', options.port); + this._webServer.listen(this.options.port, this.options.host, () => { + debug('WebHook listening on port %s', this.options.port); }); }