added CORS
This commit is contained in:
43
source/json_settings.cpp
Normal file
43
source/json_settings.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <fstream>
|
||||
#include "json.hpp"
|
||||
#include "json_settings.h"
|
||||
#include "crow/logging.h"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using json = nlohmann::json;
|
||||
using namespace::AppSettings;
|
||||
|
||||
Settings AppSettings::deafult(){
|
||||
return Settings {
|
||||
.http_port = 3010,
|
||||
.db_path = "/var/lib/shadowrun-server/shadowrun.db",
|
||||
.url = "*"
|
||||
};
|
||||
}
|
||||
|
||||
Settings AppSettings::load() {
|
||||
ifstream file(settingsFile);
|
||||
if (!file.is_open()) {
|
||||
CROW_LOG_ERROR << "Failed to load settings file" << settingsFile << " Loading default settings";
|
||||
return AppSettings::deafult();
|
||||
}
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf(); // Read the whole file into the stringstream
|
||||
std::string fileContents = buffer.str(); // Convert to std::string
|
||||
auto result = utils::parseJson(fileContents);
|
||||
|
||||
if(!result){
|
||||
CROW_LOG_ERROR << "failed to parse settings file, Loading default settings";
|
||||
return AppSettings::deafult();
|
||||
}
|
||||
|
||||
try {
|
||||
return result.value().get<Settings>();
|
||||
} catch (...) {
|
||||
CROW_LOG_ERROR << "failed to parse settings file, Loading default settings";
|
||||
return AppSettings::deafult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user