base of maps routes

This commit is contained in:
Антон 2024-03-20 18:40:04 +03:00
parent ac9c40058b
commit b2f0a8d4c3
1 changed files with 36 additions and 14 deletions

View File

@ -5,6 +5,7 @@
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <fstream>
#include "src/http_server.h" #include "src/http_server.h"
@ -32,24 +33,45 @@ struct content_type
StringResponse HandleRequest(StringRequest&& req) StringResponse HandleRequest(StringRequest&& req)
{ {
auto route = req.target(); constexpr static string_view k_MapsPattern = "/api/v1/maps"sv;
const auto route = req.target();
switch (true) if (equal(k_MapsPattern.begin(),
k_MapsPattern.end(),
route.begin(),
route.end()))
{ {
default: ifstream stream("./config.json"s);
{ string config;
StringResponse res(http::status::bad_request, 1); string buf;
res.set(http::field::content_type, content_type::k_JSON);
string body = "{\n"
" \"code\": \"badRequest\",\n"
" \"message\": \"Bad request\"\n"
"} "s;
res.body() = body;
res.content_length(body.size());
res.keep_alive(true);
return res; while (std::getline(stream, buf))
{
config += buf;
} }
auto r = config;
}
else if (equal(k_MapsPattern.begin(),
k_MapsPattern.end(),
route.begin(),
route.begin() + k_MapsPattern.size()))
{
}
else
{
StringResponse res(http::status::bad_request, 1);
res.set(http::field::content_type, content_type::k_JSON);
string body = "{\n"
" \"code\": \"badRequest\",\n"
" \"message\": \"Bad request\"\n"
"} "s;
res.body() = body;
res.content_length(body.size());
res.keep_alive(true);
return res;
} }
} }