diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index 8c590ab..5edf9f3 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -32,15 +32,33 @@ public: boost::beast::http::request>&& req ) override { - boost::beast::http::response res{ - boost::beast::http::status::ok, req.version() - }; + auto const not_found = [&req](boost::beast::string_view target) + { + boost::beast::http::response res{ + boost::beast::http::status::not_found, req.version() + }; + res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(boost::beast::http::field::content_type, "text/html"); + res.keep_alive(req.keep_alive()); + res.body() = "The resource '" + std::string(target) + "' was not found."; + res.prepare_payload(); + return res; + }; - res.body() = "{ \"detail\": \"ok\"}"; - res.set(boost::beast::http::field::content_type, "application/json"); - res.content_length(res.body().size()); + const std::string& route = req.target(); + const bool is_match_no_route = !routes_pathes_.count(route); - return res; + if (is_match_no_route) return not_found(req.target()); + + std::optional> maybe_executor_ptr = routes_pathes_ + .at(route) + ->FindExecutor(req.method()); + + if (!maybe_executor_ptr.has_value()) return not_found(req.target()); + + IRouteExecutor& executor = *maybe_executor_ptr.value(); + + return executor(std::move(req)); } }; }