mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-03 06:16:04 +00:00
Add preliminary work for HTTP health endpoint (#68)
* Add preliminary work for HTTP health endpoint * Http: Fix infinite loop bug in Tx509KeypairGenerator::generateKey() * update commandline * Add TLS Support class for use with http server * Add preliminary HTTP Server; TLS still broken; fix in later commit * Fix TLS handshake, due to server being unable to serve key/certfile in 'Http.h/Http.cpp'; Cause was httlib not being threadsafe due to being a blocking http library * Run clang format * Add option to configure http server port via ServerConfig * TConfig: add HTTPServerPort to config parsing step * Fix SSL Cert / Key path not auto generating when not existing * Add health endpoint; Fix SSL Cert serial no. not refreshing when regenerating * Switch arround status codes in /health route * Run clang format Co-authored-by: Lion Kortlepel <development@kortlepel.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "Common.h"
|
||||
#define TOML11_PRESERVE_COMMENTS_BY_DEFAULT
|
||||
|
||||
#include <toml11/toml.hpp> // header-only version of TOML++
|
||||
@@ -20,6 +21,9 @@ static constexpr std::string_view StrResourceFolder = "ResourceFolder";
|
||||
static constexpr std::string_view StrAuthKey = "AuthKey";
|
||||
static constexpr std::string_view StrSendErrors = "SendErrors";
|
||||
static constexpr std::string_view StrSendErrorsMessageEnabled = "SendErrorsShowMessage";
|
||||
static constexpr std::string_view StrSSLKeyPath = "SSLKeyPath";
|
||||
static constexpr std::string_view StrSSLCertPath = "SSLCertPath";
|
||||
static constexpr std::string_view StrHTTPServerPort = "HTTPServerPort";
|
||||
|
||||
void WriteSendErrors(const std::string& name) {
|
||||
std::ofstream CfgFile { name, std::ios::out | std::ios::app };
|
||||
@@ -43,7 +47,15 @@ TConfig::TConfig(const std::string& ConfigFileName)
|
||||
ParseFromFile(mConfigFileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes out the loaded application state into ServerConfig.toml
|
||||
*
|
||||
* This writes out the current state of application settings that are
|
||||
* applied to the server instance (i.e. the current application settings loaded in the server).
|
||||
* If the state of the application settings changes during runtime,
|
||||
* call this function whenever something about the config changes
|
||||
* whether it is in TConfig.cpp or the configuration file.
|
||||
*/
|
||||
void TConfig::FlushToFile() {
|
||||
auto data = toml::parse(mConfigFileName);
|
||||
data["General"] = toml::table();
|
||||
@@ -59,6 +71,9 @@ void TConfig::FlushToFile() {
|
||||
data["General"][StrResourceFolder.data()] = Application::Settings.Resource;
|
||||
data["General"][StrSendErrors.data()] = Application::Settings.SendErrors;
|
||||
data["General"][StrSendErrorsMessageEnabled.data()] = Application::Settings.SendErrorsMessageEnabled;
|
||||
data["General"][StrSSLKeyPath.data()] = Application::Settings.SSLKeyPath;
|
||||
data["General"][StrSSLCertPath.data()] = Application::Settings.SSLCertPath;
|
||||
data["General"][StrHTTPServerPort.data()] = Application::Settings.HTTPServerPort;
|
||||
std::ofstream Stream(mConfigFileName);
|
||||
Stream << data << std::flush;
|
||||
}
|
||||
@@ -93,6 +108,9 @@ void TConfig::CreateConfigFile(std::string_view name) {
|
||||
data["General"][StrMap.data()] = Application::Settings.MapName;
|
||||
data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
|
||||
data["General"][StrResourceFolder.data()] = Application::Settings.Resource;
|
||||
data["General"][StrSSLKeyPath.data()] = Application::Settings.SSLKeyPath;
|
||||
data["General"][StrSSLCertPath.data()] = Application::Settings.SSLCertPath;
|
||||
data["General"][StrHTTPServerPort.data()] = Application::Settings.HTTPServerPort;
|
||||
|
||||
std::ofstream ofs { std::string(name) };
|
||||
if (ofs.good()) {
|
||||
@@ -124,6 +142,9 @@ void TConfig::ParseFromFile(std::string_view name) {
|
||||
Application::Settings.ServerDesc = data["General"][StrDescription.data()].as_string();
|
||||
Application::Settings.Resource = data["General"][StrResourceFolder.data()].as_string();
|
||||
Application::Settings.Key = data["General"][StrAuthKey.data()].as_string();
|
||||
Application::Settings.SSLKeyPath = data["General"][StrSSLKeyPath.data()].as_string();
|
||||
Application::Settings.SSLCertPath = data["General"][StrSSLCertPath.data()].as_string();
|
||||
Application::Settings.HTTPServerPort = data["General"][StrHTTPServerPort.data()].as_integer();
|
||||
if (!data["General"][StrSendErrors.data()].is_boolean()
|
||||
|| !data["General"][StrSendErrorsMessageEnabled.data()].is_boolean()) {
|
||||
WriteSendErrors(std::string(name));
|
||||
@@ -154,6 +175,8 @@ void TConfig::PrintDebug() {
|
||||
beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\"");
|
||||
beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\"");
|
||||
beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\"");
|
||||
beammp_debug(std::string(StrSSLKeyPath) + ": \"" + Application::Settings.SSLKeyPath + "\"");
|
||||
beammp_debug(std::string(StrSSLCertPath) + ": \"" + Application::Settings.SSLCertPath + "\"");
|
||||
// special!
|
||||
beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user