31 lines
641 B
C++
31 lines
641 B
C++
#include "GetMapsHandler.h"
|
|
|
|
#include <fstream>
|
|
|
|
namespace http_server
|
|
{
|
|
StringResponse GetMapsHandler(const StringRequest& req)
|
|
{
|
|
ifstream stream("./config.json"s);
|
|
string config;
|
|
string buf;
|
|
|
|
while (std::getline(stream, buf))
|
|
{
|
|
config += buf;
|
|
}
|
|
|
|
string_view config_ref {config.begin(), config.end()};
|
|
auto parsed_config = json::parse(config_ref);
|
|
StringResponse res(http::status::ok, 1);
|
|
res.set(http::field::content_type, content_type::k_JSON);
|
|
res.body() = json::serialize(parsed_config.as_object().at("maps"sv).as_array());
|
|
res.content_length(res.body().size());
|
|
res.keep_alive(true);
|
|
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|