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

cors issue #1636

Open
yovanoc opened this issue Feb 20, 2024 · 3 comments
Open

cors issue #1636

yovanoc opened this issue Feb 20, 2024 · 3 comments

Comments

@yovanoc
Copy link

yovanoc commented Feb 20, 2024

Bug Report

Version

├── tonic v0.11.0
├── tonic-web v0.11.0
│   ├── tonic v0.11.0 (*)
└── tonic-build v0.11.0

Platform

Darwin mbp-1.home 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:10 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6031 arm64

Description

I tried this code:

  let server = HealthServer { addr };

  let svc = pb::health_server::HealthServer::with_interceptor(server, check_auth);

  let cors = CorsLayer::new()
            .allow_headers(Any)
            .allow_methods([Method::GET, Method::POST])
            .allow_origin(Any);

        let serve = Server::builder()
            .trace_fn(|_| tracing::info_span!("health_server"))
            .accept_http1(true)
            .layer(cors)
            .layer(GrpcWebLayer::new())
            .add_service(svc)
            .serve(addr);

I expected to see this happen: should build

Instead, this happened:
Screenshot 2024-02-20 at 13 27 22

@boan-anbo
Copy link

boan-anbo commented Mar 7, 2024

Same issue. My Grpc-web setup with cors was working fine before upgrading to 11.0 from 10.02.

    Server::builder()
        .accept_http1(true)
        .layer(CorsLayer::new())
        .layer(GrpcWebLayer::new())
        .add_service(reflection_service)
        .serve(address)
        .await
     

My error:

error[E0277]: the trait bound `Cors<GrpcWebService<Routes>>: tonic::codegen::Service<request::Request<toni
c::transport::Body>>` is not satisfied
   --> src\launch\launch_server.rs:164:10
    |
164 |         .serve(address)
    |          ^^^^^ the trait `tonic::codegen::Service<request::Request<tonic::transport::Body>>` is not 
implemented for `Cors<GrpcWebService<Routes>>`
    |
    = help: the trait `tonic::codegen::Service<http::request::Request<ReqBody>>` is implemented for `Cors<
S>`

I look at #1320 several times, but the examples simply don't work with 11.0.

@boan-anbo
Copy link

boan-anbo commented Mar 7, 2024

I found the issue: tonic 0.11.0 doesn't work with tower-http 0.5.0 above.

Downgrading tower-http to 0.4.4 allows tonic 0.11.0 Cors layer to compile.

@Emulator000
Copy link

I think is same as this issue: #1678

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