From 01a1b67bb4f616c511c9b8fea5798bd881be14e3 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 12 Jul 2015 14:29:43 +0200 Subject: [PATCH] bind requestListener function on createServer --- src/telegram.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/telegram.js b/src/telegram.js index c7f0048..61a4c19 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -53,26 +53,22 @@ var TelegramBot = function (token, options) { util.inherits(TelegramBot, EventEmitter); TelegramBot.prototype._configureWebHook = function (port, host, key, cert) { - var protocol = 'HTTP'; - var self = this; + var binded = this._requestListener.bind(this); if (key && cert) { // HTTPS Server - protocol = 'HTTPS'; + debug('HTTPS WebHook enabled'); var options = { key: fs.readFileSync(key), cert: fs.readFileSync(cert) }; - this._webServer = https.createServer(options, function (req, res) { - self._requestListener.call(self, req, res); - }); - } else { // HTTP Server - this._webServer = http.createServer(function (req, res) { - self._requestListener.call(self, req, res); - }); + this._webServer = https.createServer(options, binded); + } else { + debug('HTTP WebHook enabled'); + this._webServer = http.createServer(binded); } this._webServer.listen(port, host, function () { - console.log(protocol+" WebHook listening on:", port); + debug("WebHook listening on port %s", port); }); };