axum-reverse-proxy 1.3.0

A flexible and efficient reverse proxy implementation for Axum web applications
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use axum::{Router, serve};
use axum_reverse_proxy::BalancedProxy;
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
    // Forward /api to two upstream servers
    let proxy = BalancedProxy::new(
        "/api",
        vec!["https://api1.example.com", "https://api2.example.com"],
    );
    let app: Router = proxy.into();

    let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
    println!("Server running on http://localhost:3000");
    serve(listener, app).await.unwrap();
}