[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.
experimental
GochoMugo 9 years ago
parent 0174b875ff
commit aaa3992a78
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
  1. 16
      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);
});
}

Loading…
Cancel
Save