add file support

This commit is contained in:
Антон 2024-03-26 08:25:28 +03:00
parent 6ddf982780
commit 935336d271
1 changed files with 6 additions and 20 deletions

View File

@ -68,21 +68,7 @@ StringResponse HandleRequest(StringRequest&& req)
FileResponse HandleRequestFile(StringRequest&& req)
{
const auto route = req.target();
if (req.target() == "/"sv || find(route.begin(), route.end(), '.') != route.end())
{
return GetStaticAssetHandler(req);
}
else
{
FileResponse res(http::status::not_found, 1);
res.set(http::field::content_type, content_type::k_JSON);
res.content_length(0);
res.keep_alive(true);
return res;
}
return GetStaticAssetHandler(req);
}
// Запускает функцию fn на n потоках, включая текущий
@ -126,12 +112,12 @@ int main()
constexpr net::ip::port_type port = 8080;
http_server::ServeHttp(ioc, {address, port}, [](auto&& req, auto&& sender)
{
sender(HandleRequestFile(std::forward<decltype(req)>(req)));
});
const auto route = req.target();
http_server::ServeHttp(ioc, {address, port + 1}, [](auto&& req, auto&& sender)
{
sender(HandleRequest(std::forward<decltype(req)>(req)));
if (req.target() == "/"sv || find(route.begin(), route.end(), '.') != route.end())
sender(HandleRequestFile(std::forward<decltype(req)>(req)));
else
sender(HandleRequest(std::forward<decltype(req)>(req)));
});
net::steady_timer t {ioc, 30s};