Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default fallback in tonic::service::Routes; #1955

Open
nduchenk opened this issue Sep 25, 2024 · 0 comments
Open

Remove default fallback in tonic::service::Routes; #1955

nduchenk opened this issue Sep 25, 2024 · 0 comments

Comments

@nduchenk
Copy link

Feature Request

Motivation

Sorry for raising this issue if I missed some info.
Can't use tonic Routes with axum router with its own fallback:
Cannot merge two Routers that both have a fallback. This is an axum error, but it appears that tonic Routes by default set fallback:

router: axum::Router::new().fallback(unimplemented),

As a result in example like this you receive an error, then have to find where another fallback comes from so to overwrite it or if you don'y use any fallback you get one from tonic Routes for all of your handlers which might be unexpected or not very obvious.

async fn hello() -> impl axum::response::IntoResponse {
    "Hello, World!"
}

async fn im_a_teapot() -> impl axum::response::IntoResponse {
    (StatusCode::IM_A_TEAPOT, "IM_A_TEAPOT")
}

#[tokio::main]
async fn main() {
    let app = Router::new().route("/hello", get(hello));
    // .fallback(im_a_teapot); <--- if added will fail in runtime.

    let tonic_routes = Routes::new(EchoServer::new(MyEcho)).into_axum_router();
    let app = app.merge(tonic_routes);

    let listener = tokio::net::TcpListener::bind("127.0.0.1:8000")
        .await
        .unwrap();

    axum::serve(listener, app).await.unwrap();
}

Proposal

Remove default fallback from:

router: axum::Router::new().fallback(unimplemented),

Alternatives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant