cors issue
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:
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.
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.
I think is same as this issue: https://github.com/hyperium/tonic/issues/1678