From 8b125c7775215cd0cf2218f08dc1dc946e58dd4b Mon Sep 17 00:00:00 2001 From: Albert S Date: Thu, 21 Feb 2019 10:47:49 +0100 Subject: [PATCH] httpgateway: take listen/port data from config file --- gateway/httpgateway.cpp | 13 ++++++++++++- gateway/httpgateway.h | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gateway/httpgateway.cpp b/gateway/httpgateway.cpp index bfd7ee0..c7b2e80 100644 --- a/gateway/httpgateway.cpp +++ b/gateway/httpgateway.cpp @@ -22,6 +22,17 @@ SOFTWARE. #include "../logger.h" HttpGateway::HttpGateway(const Config &config) { + this->listenaddr = config.getConfig("http.listenaddr"); + if(this->listenaddr.empty()) + { + throw new std::runtime_error("No http.listenaddr in config file"); + } + std::string listenport = config.getConfig("http.listenport"); + if(listenport.empty()) + { + throw new std::runtime_error("No http.listenport in config file"); + } + this->listenport = std::stoi(listenport); } bool HttpGateway::keepReading() @@ -89,5 +100,5 @@ void HttpGateway::work(RequestWorker &worker) }; server.Get("/(.*)", handler); server.Post("/(.*)", handler); - server.listen("127.0.0.1", 1234); + server.listen(this->listenaddr.c_str(), this->listenport); } diff --git a/gateway/httpgateway.h b/gateway/httpgateway.h index 50fb97d..f3317ef 100644 --- a/gateway/httpgateway.h +++ b/gateway/httpgateway.h @@ -13,6 +13,10 @@ class HttpGateway : public GatewayInterface httplib::Response convertResponse(Response response); Request convertRequest(httplib::Request request); // void worker(const httplib::Request& req, httplib::Response& res); + + std::string listenaddr; + int listenport; + public: HttpGateway(const Config &config); bool keepReading() override;