use axum::routing::{on, MethodFilter, MethodRouter};
use crate::core::engine::FrozenDiContainer;
use crate::core::plugins::PluginRoute;
#[doc(hidden)]
pub fn build_plugin_route(
container: &'static FrozenDiContainer,
route: &PluginRoute,
globals: &'static [&'static dyn crate::web::interceptors::Interceptor],
filters: &'static [&'static dyn crate::web::boundary::BoundaryFilter],
) -> MethodRouter {
let filter = MethodFilter::try_from(axum::http::Method::from(route.method))
.expect("supported HTTP method");
let chain = crate::web::interceptors::compose_chain(globals, route.handler.clone());
let pattern = route.path;
let handler = move |req: axum::extract::Request| {
let chain = chain.clone();
async move {
let (parts, body) = req.into_parts();
crate::web::boundary::run_entry(
parts,
body,
Default::default(),
container,
pattern,
None,
filters,
&chain,
)
.await
}
};
on(filter, handler)
}