Add UseSSL option to server config

This commit is contained in:
Lion Kortlepel
2021-12-06 13:47:07 +01:00
parent a1335e8c7d
commit 3cce875fbb
4 changed files with 69 additions and 43 deletions

View File

@@ -270,16 +270,21 @@ Http::Server::THttpServerInstance::THttpServerInstance() {
}
void Http::Server::THttpServerInstance::operator()() {
beammp_info("HTTPS Server started on port " + std::to_string(Application::Settings.HTTPServerPort));
httplib::SSLServer HttpLibServerInstance { Application::Settings.SSLCertPath.c_str(), Application::Settings.SSLKeyPath.c_str() };
beammp_info("HTTP(S) Server started on port " + std::to_string(Application::Settings.HTTPServerPort));
std::unique_ptr<httplib::Server> HttpLibServerInstance;
if (Application::Settings.HTTPServerUseSSL) {
HttpLibServerInstance = std::make_unique<httplib::SSLServer>(Application::Settings.SSLCertPath.c_str(), Application::Settings.SSLKeyPath.c_str());
} else {
HttpLibServerInstance = std::make_unique<httplib::Server>();
}
// todo: make this IP agnostic so people can set their own IP
HttpLibServerInstance.Get("/", [](const httplib::Request&, httplib::Response& res) {
HttpLibServerInstance->Get("/", [](const httplib::Request&, httplib::Response& res) {
res.set_content("<!DOCTYPE html><article><h1>Hello World!</h1><section><p>BeamMP Server can now serve HTTP requests!</p></section></article></html>", "text/html");
});
HttpLibServerInstance.Get("/health", [](const httplib::Request&, httplib::Response& res) {
HttpLibServerInstance->Get("/health", [](const httplib::Request&, httplib::Response& res) {
res.set_content("0", "text/plain");
res.status = 200;
});
Application::SetSubsystemStatus("HTTPServer", Application::Status::Good);
HttpLibServerInstance.listen("0.0.0.0", Application::Settings.HTTPServerPort);
HttpLibServerInstance->listen("0.0.0.0", Application::Settings.HTTPServerPort);
}