httpgateway: take listen/port data from config file

This commit is contained in:
Albert S. 2019-02-21 10:47:49 +01:00
parent f5b594449d
commit 8b125c7775
2 changed files with 16 additions and 1 deletions

View File

@ -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);
}

View File

@ -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;