fix(web): Fix enable and update docs (#1326)

* fix(web): Fix `enable` and update docs

* fix example, update deny

* fix namedservice path
This commit is contained in:
Lucio Franco
2023-03-20 17:04:46 +00:00
committed by GitHub
parent 69ce71efa6
commit a9db219e50
3 changed files with 63 additions and 23 deletions
+1 -9
View File
@@ -2,8 +2,6 @@ use tonic::{transport::Server, Request, Response, Status};
use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use tonic_web::GrpcWebLayer;
use tower_http::cors::CorsLayer;
pub mod hello_world {
tonic::include_proto!("helloworld");
@@ -41,13 +39,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Server::builder()
// GrpcWeb is over http1 so we must enable it.
.accept_http1(true)
// Use the Cors layer from `tower-http`.
.layer(CorsLayer::new())
// Apply the tonic-web layer to convert
// http1 requests into something that
// the core tonic code can understand.
.layer(GrpcWebLayer::new())
.add_service(greeter)
.add_service(tonic_web::enable(greeter))
.serve(addr)
.await?;