tonic icon indicating copy to clipboard operation
tonic copied to clipboard

cors issue

Open yovanoc opened this issue 1 year ago • 3 comments

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

yovanoc avatar Feb 20 '24 12:02 yovanoc

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 avatar Mar 07 '24 07:03 boan-anbo

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.

boan-anbo avatar Mar 07 '24 07:03 boan-anbo

I think is same as this issue: https://github.com/hyperium/tonic/issues/1678

Emulator000 avatar May 01 '24 15:05 Emulator000