#include namespace seafire::routing { void flatten(std::vector& endpoints, std::string const& vhost, 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(vhost, path, server::make_middleware(middlewares, *h)); } // flatten any child routes. // for (auto const& child_route : route.children()) { flatten(endpoints, vhost, middlewares, child_route, route.path().empty() ? path : path + '/'); } } void flatten(std::vector& endpoints, std::string const& vhost, std::vector middlewares, route_t const& r) { flatten(endpoints, vhost, middlewares, r, "/"); } std::vector flatten(std::string const& vhost, route_t const& r) { std::vector endpoints; flatten(endpoints, vhost, {}, r); return endpoints; } } // namespace seafire::routing