From dfd547bf1bf7af0b611c4b05869298d471c3e2e9 Mon Sep 17 00:00:00 2001 From: Denis Volkov Date: Wed, 11 Oct 2017 12:40:08 +0500 Subject: [PATCH 1/3] Added Path variable to Middleware for working with non-root URLS --- lib/middleware.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 4a64297..21da923 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -4,7 +4,7 @@ const express = require('express'); const bodyParser = require('body-parser'); const stream = require('stream'); -function Middleware(logger, messageValidatorService) { +function Middleware(logger, messageValidatorService, path) { this._logger = logger; this._stream = this._createStream(); this._buffer = null; @@ -13,7 +13,7 @@ function Middleware(logger, messageValidatorService) { this._app.use(bodyParser.text({ type: "*/*" })); this._validateMessageSignature(messageValidatorService); - this._configureEndpoints(); + this._configureEndpoints(path); } Middleware.prototype.getIncoming = function() { @@ -24,14 +24,14 @@ Middleware.prototype.getStream = function() { return this._stream; }; -Middleware.prototype._configureEndpoints = function() { +Middleware.prototype._configureEndpoints = function(path) { const self = this; - this._app.get("/ping", (request, response) => { + this._app.get(path+"/ping", (request, response) => { response.send("pong"); response.end(); }); - this._app.post("/", (request, response) => { + this._app.post(path+"/", (request, response) => { self._logger.debug("Request data:", request.body); self._stream.push(request.body); From ee63406a5002bed30269a3259c94527eafc344bc Mon Sep 17 00:00:00 2001 From: Denis Volkov Date: Wed, 11 Oct 2017 15:40:14 +0500 Subject: [PATCH 2/3] Added Path variable to Middleware for running bot on non-root URLS, (like site.com/bot/viber) or multiple bots (like site.com/bot/1 and site.com/bot/2) --- lib/middleware.js | 8 ++++---- lib/viber-bot.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 21da923..10b10d8 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -8,7 +8,7 @@ function Middleware(logger, messageValidatorService, path) { this._logger = logger; this._stream = this._createStream(); this._buffer = null; - + this._path=path; this._app = express(); this._app.use(bodyParser.text({ type: "*/*" })); @@ -24,14 +24,14 @@ Middleware.prototype.getStream = function() { return this._stream; }; -Middleware.prototype._configureEndpoints = function(path) { +Middleware.prototype._configureEndpoints = function() { const self = this; - this._app.get(path+"/ping", (request, response) => { + this._app.get(self._path+"/ping", (request, response) => { response.send("pong"); response.end(); }); - this._app.post(path+"/", (request, response) => { + this._app.post(self._path+"/", (request, response) => { self._logger.debug("Request data:", request.body); self._stream.push(request.body); diff --git a/lib/viber-bot.js b/lib/viber-bot.js index 201c612..443a7f8 100644 --- a/lib/viber-bot.js +++ b/lib/viber-bot.js @@ -56,7 +56,7 @@ function ViberBot(loggerOrConfiguration, configuration) { this._logger = logger; this._client = new ViberClient(this._logger, this, API_URL, configuration.registerToEvents || SUBSCRIBED_EVENTS); - this._middleware = new Middleware(this._logger, new MessageValidator(this._logger, this.authToken)); + this._middleware = new Middleware(this._logger, new MessageValidator(this._logger, this.authToken),configuration.path); this._messageFactory = new MessageFactory(this._logger); this._regexMatcherRouter = new RegexMatcherRouter(this._logger); this._callbacks = { [EventConsts.CONVERSATION_STARTED]: []}; From 810f231291ab5ece67373098cc253ef1680e0929 Mon Sep 17 00:00:00 2001 From: Denis Volkov Date: Wed, 11 Oct 2017 15:41:59 +0500 Subject: [PATCH 3/3] Added Path variable to Middleware for running bot on non-root URLS, (like site.com/bot/viber) or multiple bots (like site.com/bot/1 and site.com/bot/2) --- lib/middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleware.js b/lib/middleware.js index 10b10d8..fc03acf 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -13,7 +13,7 @@ function Middleware(logger, messageValidatorService, path) { this._app.use(bodyParser.text({ type: "*/*" })); this._validateMessageSignature(messageValidatorService); - this._configureEndpoints(path); + this._configureEndpoints(); } Middleware.prototype.getIncoming = function() {