-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to do anything about cors. #1524
Comments
Hi, Server::builder()
.accept_http1(true)
.layer(
CorsLayer::new()
.allow_origin(AllowOrigin::mirror_request())
.allow_credentials(true)
.max_age(DEFAULT_MAX_AGE)
.expose_headers(
DEFAULT_EXPOSED_HEADERS
.iter()
.cloned()
.map(HeaderName::from_static)
.collect::<Vec<HeaderName>>(),
)
.allow_headers(
DEFAULT_ALLOW_HEADERS
.iter()
.cloned()
.map(HeaderName::from_static)
.collect::<Vec<HeaderName>>(),
),
)
.layer(GrpcWebLayer::new())
.add_service(greeter)
.serve(addr)
.await?; |
Thank you I really appreciate the help. Until grpc echosystem little bit matures tho i think i will stick with rest for now |
Setting the cors layer doesn't seem to work. Gives a trait bound error the on .serve()... |
I have the same issue: see also #1636 |
I came across a couple of discussions and a PR concerning cors however none of the explanations in the docs about cors make any sense and there isnt a single example showing how to use a cors layer.
Docs state one can customize cors config but for some reason the author has no explanation for how to do that and the example following that statement has nothing to do with cors. Unfortunately, contrary to the belief of the author most of us dont have physic powers.
There's a CorsGrpcWeb struct in the project however that as well has no explanation or a constructor.
Seems adding a third party library -tower- should fix this issue but adding tower cors layer also didnt seem to fix the cors issue. It is obvious i did something wrong there but since the documentation just expects us to know how to do this out of the womb.
Overall I just thought using grpc can improve development speed since the client and server stubs are just auto generated so no need to do double job by writing a rest endpoint for everything and then writing a request for that endpoint on client-side I was sooo wrong. Just wasted hours trying to get cors running for a project that claims to be a grpc framework with web support which seems to be lacking most basic things to get started.
The text was updated successfully, but these errors were encountered: