code: Initial Commit
This commit is contained in:
22
src/config/Config.cpp
Normal file
22
src/config/Config.cpp
Normal 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
19
src/config/Config.hpp
Normal 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;
|
||||
Reference in New Issue
Block a user