code: Initial Commit

This commit is contained in:
Vaxry
2025-04-12 20:06:56 +01:00
parent cf925610f4
commit fdc616ac69
23 changed files with 1349 additions and 0 deletions

22
src/config/Config.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "Config.hpp"
#include <glaze/glaze.hpp>
#include "../GlobalState.hpp"
static std::string readFileAsText(const std::string& path) {
std::ifstream ifs(path);
auto res = std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
if (res.back() == '\n')
res.pop_back();
return res;
}
CConfig::CConfig() {
auto json = glz::read_jsonc<SConfig>(readFileAsText(g_pGlobalState->cwd + "/" + g_pGlobalState->configPath));
if (!json.has_value())
throw std::runtime_error("No config / bad config format");
m_config = json.value();
}

19
src/config/Config.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <string>
#include <memory>
class CConfig {
public:
CConfig();
struct SConfig {
int port = 3001;
std::string forward_address = "127.0.0.1:3000";
std::string data_dir = "";
std::string html_dir = "";
unsigned long int max_request_size = 10000000; // 10MB
} m_config;
};
inline std::unique_ptr<CConfig> g_pConfig;