axum-tonic's People
axum-tonic's Issues
Handle `tonic::Status` errors like `tonic::transport::Server` does
tonic::transport::Server
uses a RecoverError
middleware to convert tonic::Status
errors into a http::Response
:
As far as I can tell, axum_tonic
doesn't handle converting tonic::Status
into response (I understand it's not possible to implement IntoResponse
for tonic::Status
).
And there's no way to use the above middleware since it's not public... I don't really understand what the middleware does, but it seems fairly complicated.
How to have permissive CORS?
I tried running a simple Echo example from the tonic sources using this axum. It seems I am unable to get the CORS policy working any ideas?
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8080/grpc.Echo/UnaryEcho. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8080/grpc.Echo/UnaryEcho. (Reason: CORS request did not succeed). Status code: (null).
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let echo_service = tonic_web::config()
.allow_all_origins()
.expose_headers([ACCESS_CONTROL_ALLOW_ORIGIN])
.enable(EchoServer::new(Echo::default()));
let cors = CorsLayer::new()
.allow_methods(Any)
.allow_headers(Any)
.expose_headers(Any)
.allow_origin(Any);
let grpc_router = Router::new()
.nest_tonic(echo_service)
.layer(cors.clone());
let rest_router = Router::new()
.route("/users", post(user_service::create_user))
.layer(cors.clone())
.merge(SwaggerUi::new("/swagger-ui/*tail").url("/api-doc/openapi.json", ApiDoc::openapi()));
let service = RestGrpcService::new(rest_router, grpc_router).into_make_service();
axum::Server::bind(&"127.0.0.1:8080".parse().unwrap()).serve(service).await.unwrap();
Ok(())
Incompatible Grpcweblayer
I am trying to enable the grpcweblayer of tonic/tonic-web:
use tonic_web::GrpcWebLayer;
//Service 1
let service_implementation_1 = MyService::new();
let new_service_1 = ServiceServer::new(service_implementation_1);
// The first grpc-service.
let grpc_router_1 = Router::new()
.nest_tonic(new_service_1)
.layer(GrpcWebLayer::new());
This results in the following compiler error:
type mismatch resolving `<Route as tower_service::Service<hyper::Request<hyper::Body>>>::Response == hyper::Response<UnsyncBoxBody<bytes::Bytes, Status>>`
expected struct `hyper::Response<UnsyncBoxBody<_, axum::Error>>`
found struct `hyper::Response<UnsyncBoxBody<_, Status>>`
Perhaps there is an easy way to map the tonic::Status to an axum::Error? Did anyone else run into this? I will try to find a solution.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.