#include namespace seafire::routing { void flatten_route(std::vector& endpoints, std::vector middlewares, route_t const& route, std::string const& root) { auto const path = root + route.path(); // append any middlewares if we have any. // for (auto const& m : route.middleware()) { middlewares.emplace_back(m); } // generate an endpoint for this route if we have a handler. // if (auto const& h = route.handler()) { endpoints.emplace_back(path, server::make_middleware(middlewares, *h)); } // flatten any child routes. // for (auto const& child_route : route.children()) { flatten_route(endpoints, middlewares, child_route, route.path().empty() ? path : path + '/'); } } void flatten_route(std::vector& endpoints, route_t const& r) { flatten_route(endpoints, {}, r, "/"); } std::vector flatten_route(route_t const& r) { std::vector endpoints; flatten_route(endpoints, r); return endpoints; } } // namespace seafire::routing