use crate::proxy::ReverseProxy;
use axum::routing::Router;
use hyper_util::client::legacy::connect::Connect;
impl<C, S> From<ReverseProxy<C>> for Router<S>
where
C: Connect + Clone + Send + Sync + 'static,
S: Send + Sync + Clone + 'static,
{
fn from(proxy: ReverseProxy<C>) -> Self {
let path = proxy.path().to_string();
let proxy_router = Router::<S>::new().fallback_service(proxy);
if ["", "/"].contains(&path.as_str()) {
proxy_router
} else {
Router::new().nest(&path, proxy_router)
}
}
}
use crate::balanced_proxy::{BalancedProxy, DiscoverableBalancedProxy};
impl<C, S> From<BalancedProxy<C>> for Router<S>
where
C: Connect + Clone + Send + Sync + 'static,
S: Send + Sync + Clone + 'static,
{
fn from(proxy: BalancedProxy<C>) -> Self {
let path = proxy.path().to_string();
let proxy_router = Router::<S>::new().fallback_service(proxy);
if ["", "/"].contains(&path.as_str()) {
proxy_router
} else {
Router::new().nest(&path, proxy_router)
}
}
}
impl<C, D, S> From<DiscoverableBalancedProxy<C, D>> for Router<S>
where
C: Connect + Clone + Send + Sync + 'static,
D: tower::discover::Discover + Clone + Send + Sync + 'static,
D::Service: Into<String> + Send,
D::Key: Clone + std::fmt::Debug + Send + Sync + std::hash::Hash,
D::Error: std::fmt::Debug + Send,
S: Send + Sync + Clone + 'static,
{
fn from(proxy: DiscoverableBalancedProxy<C, D>) -> Self {
let path = proxy.path().to_string();
let proxy_router = Router::<S>::new().fallback_service(proxy);
if ["", "/"].contains(&path.as_str()) {
proxy_router
} else {
Router::new().nest(&path, proxy_router)
}
}
}