From 137e38d035e570a948065d8cd208bc348a8f8e63 Mon Sep 17 00:00:00 2001 From: Yang Jing Date: Thu, 12 Sep 2024 01:21:32 +0800 Subject: [PATCH] fix --- crates/ultimate-grpc/src/utils.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/ultimate-grpc/src/utils.rs b/crates/ultimate-grpc/src/utils.rs index ce3f4d3..1826943 100644 --- a/crates/ultimate-grpc/src/utils.rs +++ b/crates/ultimate-grpc/src/utils.rs @@ -1,7 +1,7 @@ use futures::{Future, TryFutureExt}; use prost_types::FieldMask; use tonic::{metadata::MetadataMap, service::RoutesBuilder, transport::Server, Status}; -use tower_http::trace::TraceLayer; +use tower_http::{compression::CompressionLayer, trace::TraceLayer}; use ultimate::{ configuration::model::{GrpcConf, SecurityConf}, security::{jose::JwtPayload, SecurityUtils}, @@ -18,13 +18,12 @@ where { let grpc_addr = conf.server_addr.parse()?; - #[cfg(not(feature = "tonic-web"))] - let b = Server::builder(); + let mut b = Server::builder().layer(CompressionLayer::new()).layer(TraceLayer::new_for_grpc()); + #[cfg(feature = "tonic-web")] - let b = Server::builder().accept_http1(true).layer(tonic_web::GrpcWebLayer::new()); + let mut b = b.accept_http1(true).layer(tonic_web::GrpcWebLayer::new()); let mut routes_builder = RoutesBuilder::default(); - f(&mut routes_builder); #[cfg(feature = "tonic-reflection")] @@ -38,8 +37,7 @@ where // let s = router.into_service(); - let serve = - b.layer(TraceLayer::new_for_grpc()).add_routes(routes_builder.routes()).serve(grpc_addr).map_err(DataError::from); + let serve = b.add_routes(routes_builder.routes()).serve(grpc_addr).map_err(DataError::from); Ok(serve) }