mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 06:21:28 +00:00
[Library] Update httplib (#1401)
* Update httplib * Update syntax for new httplib and run on own thread * Only log if path is set in request
This commit is contained in:
parent
3886636ec7
commit
7139530787
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
LoginServer server;
|
||||
EQEmuLogSys LogSys;
|
||||
@ -130,6 +131,23 @@ void LoadServerConfig()
|
||||
);
|
||||
}
|
||||
|
||||
void start_web_server()
|
||||
{
|
||||
int web_api_port = server.config.GetVariableInt("web_api", "port", 6000);
|
||||
LogInfo("Webserver API now listening on port [{0}]", web_api_port);
|
||||
|
||||
httplib::Server api;
|
||||
|
||||
api.set_logger([](const auto& req, const auto& res) {
|
||||
if (!req.path.empty()) {
|
||||
LogInfo("[API] Request [{}] via [{}:{}]", req.path, req.remote_addr, req.remote_port);
|
||||
}
|
||||
});
|
||||
|
||||
LoginserverWebserver::RegisterRoutes(api);
|
||||
api.listen("0.0.0.0", web_api_port);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
RegisterExecutablePlatform(ExePlatformLogin);
|
||||
@ -195,7 +213,7 @@ int main(int argc, char **argv)
|
||||
* create client manager
|
||||
*/
|
||||
LogInfo("Client Manager Init");
|
||||
server.client_manager = new ClientManager();
|
||||
server.client_manager = new ClientManager();
|
||||
if (!server.client_manager) {
|
||||
LogError("Client Manager Failed to Start");
|
||||
LogInfo("Server Manager Shutdown");
|
||||
@ -222,13 +240,10 @@ int main(int argc, char **argv)
|
||||
/**
|
||||
* Web API
|
||||
*/
|
||||
httplib::Server api;
|
||||
int web_api_port = server.config.GetVariableInt("web_api", "port", 6000);
|
||||
bool web_api_enabled = server.config.GetVariableBool("web_api", "enabled", true);
|
||||
bool web_api_enabled = server.config.GetVariableBool("web_api", "enabled", true);
|
||||
if (web_api_enabled) {
|
||||
api.bind("0.0.0.0", web_api_port);
|
||||
LogInfo("Webserver API now listening on port [{0}]", web_api_port);
|
||||
LoginserverWebserver::RegisterRoutes(api);
|
||||
std::thread web_api_thread(start_web_server);
|
||||
web_api_thread.detach();
|
||||
}
|
||||
|
||||
LogInfo("[Config] [Logging] IsTraceOn [{0}]", server.options.IsTraceOn());
|
||||
@ -251,10 +266,6 @@ int main(int argc, char **argv)
|
||||
server.client_manager->Process();
|
||||
EQ::EventLoop::Get().Process();
|
||||
|
||||
if (web_api_enabled) {
|
||||
api.poll();
|
||||
}
|
||||
|
||||
Sleep(5);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user