2023-04-03 08:57:51 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
Config load_config(const char* path) {
|
|
|
|
File config_file(path, "r");
|
2023-04-10 14:20:29 +00:00
|
|
|
return nlohmann::json::parse(config_file.get());
|
2023-04-03 08:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void from_json(const nlohmann::json& j, Config& config) {
|
|
|
|
using namespace std::string_literals;
|
|
|
|
|
|
|
|
j.at("bind_host").get_to(config.bind_host);
|
|
|
|
j.at("bind_port").get_to(config.bind_port);
|
|
|
|
if (config.bind_port < 0) {
|
|
|
|
throw std::invalid_argument("Invalid port to bind to: "s + std::to_string(config.bind_port));
|
|
|
|
}
|
2023-04-06 12:24:09 +00:00
|
|
|
config.image_proxy_url = j.at("image_proxy_url").get<std::string>();
|
2023-06-04 05:08:49 +00:00
|
|
|
if (j.contains("canonical_origin") && j["canonical_origin"].is_string()) {
|
|
|
|
config.canonical_origin = j["canonical_origin"].get<std::string>();
|
|
|
|
}
|
2023-04-03 08:57:51 +00:00
|
|
|
}
|