56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#include <seafire/routing/flatten.hxx>
|
|
|
|
namespace seafire::routing
|
|
{
|
|
|
|
void
|
|
flatten(std::vector<endpoint_t>& endpoints,
|
|
std::string const& vhost,
|
|
std::vector<server::middleware_t> 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<endpoint_t>& endpoints,
|
|
std::string const& vhost,
|
|
std::vector<server::middleware_t> middlewares,
|
|
route_t const& r)
|
|
{
|
|
flatten(endpoints, vhost, middlewares, r, "/");
|
|
}
|
|
|
|
std::vector<endpoint_t>
|
|
flatten(std::string const& vhost, route_t const& r)
|
|
{
|
|
std::vector<endpoint_t> endpoints;
|
|
flatten(endpoints, vhost, {}, r);
|
|
return endpoints;
|
|
}
|
|
|
|
} // namespace seafire::routing
|