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

tonic_web: NamedService bound on enable() required #1177

Closed
softdevca opened this issue Dec 1, 2022 · 6 comments
Closed

tonic_web: NamedService bound on enable() required #1177

softdevca opened this issue Dec 1, 2022 · 6 comments

Comments

@softdevca
Copy link

softdevca commented Dec 1, 2022

Bug Report

It was proposed to remove the NamedService bound of tonic_web::enable() in issue #1115. This change was accepted but it breaks adding the enable'd service to a Tonic server.

Issue #1174 was briefly filed and closed with a work around.

Version

├── tonic v0.8.3
├── tonic-web v0.5.0
│   ├── tonic v0.8.3 (*)
└── tonic-build v0.8.4

Platform

MacOS 13.0.1 on M1 Pro, rust 1.65.0
Pop OS Linux on AMD, rust 1.65.0

Description

The standard example below will not compile because add_service requires the NamedService trait and tonic_web::enable no longer provides it.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = "[::1]:50051".parse().unwrap();
    let greeter = GreeterServer::new(MyGreeter::default());

    Server::builder()
       .accept_http1(true)
       .add_service(tonic_web::enable(greeter))
       .serve(addr)
       .await?;

   Ok(())
}
@stepan-romankov
Copy link

Same here.

@LucioFranco
Copy link
Member

I believe https://github.com/hyperium/tonic/blob/master/examples/src/grpc-web/server.rs#L42 should work for you?

@stepan-romankov
Copy link

stepan-romankov commented Dec 12, 2022

I believe https://github.com/hyperium/tonic/blob/master/examples/src/grpc-web/server.rs#L42 should work for you?

Thanks @LucioFranco, works like a charm! I assume documentation needs to be fixed...

@softdevca
Copy link
Author

It worked for me as well, though I had to add the Cors layer manual now that I cannot use tonic_web::enable().

@LucioFranco
Copy link
Member

Ah yup those docs need to be updated!

@softdevca yeah the cors stuff got removed iirc, you can check the PRs we made for tonic-web to see the background.

@LucioFranco
Copy link
Member

Gonna close this since I think we got this all resolved.

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

3 participants