Skip to content

How to combine tonic-web and axum with a "mini-proxy" #1111

Answered by nguiard
nguiard asked this question in Q&A
Discussion options

You must be logged in to vote

After a bit a research involving some convoluted ways, it turns this is actually very easy. As tonic and tonic-web-wrapped services implement Service from tower-service, you can simply create your axum app and wrap your tonic-web service in axum::routing::any_service. Works great, still answers direct non-web gRPC too (you probably need to have the http2 feature of axum enabled). No need for weird url prefix, rewriting or anything:

    let grpc_web_greeter = tonic_web::enable(GreeterServer::new(GreeterStruct));
    let axum_addr = "[::]:50051".parse()?;
    let web_app = axum::Router::new()
        .route(
            "/greeter.Greeter/*rpc", 
            axum::routing::any_service(grpc_w…

Replies: 2 comments 11 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
11 replies
@HuakunShen
Comment options

@HuakunShen
Comment options

@JamieMair
Comment options

@anotherchudov
Comment options

@rynoV
Comment options

Answer selected by nguiard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants