mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-04 06:46:23 +00:00
Add UseSSL option to server config
This commit is contained in:
15
src/Http.cpp
15
src/Http.cpp
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user