Skip to content
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

CORS docs wrong - Service needed #1071

Open
tennox opened this issue Mar 3, 2025 · 5 comments
Open

CORS docs wrong - Service needed #1071

tennox opened this issue Mar 3, 2025 · 5 comments

Comments

@tennox
Copy link
Contributor

tennox commented Mar 3, 2025

Problem

Took me hours of debugging to figure out the example on salvo_cors docs is wrong:

let router = Router::new().hoop(cors_handler).get(hello);

the server responds with a 405 Method Not Allowed to a preflight request:

❯ http OPTIONS http://localhost:5800
HTTP/1.1 405 Method Not Allowed

Solution

The only way it works is if the cors handler is added to a service (like I found in examples/cors on this repo):

let service = Service::new(
        Router::new().get(hello),
).hoop(Cors::very_permissive().into_handler());
Server::new(acceptor).serve(service).await;
❯ http OPTIONS http://localhost:8000
HTTP/1.1 204 No Content
@tennox
Copy link
Contributor Author

tennox commented Mar 3, 2025

Or is this actually a bug, not a docs problem?

@chrislearn
Copy link
Member

You can give document repository a PR.
https://github.com/salvo-rs/website

tennox added a commit to tennox/salvo that referenced this issue Mar 3, 2025
@tennox
Copy link
Contributor Author

tennox commented Mar 3, 2025

#1072

@tennox
Copy link
Contributor Author

tennox commented Mar 3, 2025

Or is this actually a bug, not a docs problem?

I guess the change was introduced in this commit:
ff4c1be#diff-f93b991bdb7ec06b8705f2ddf41de65e4a69afc0940c5c5c32b643454ec2bee1

Was it on purpose to break the router way of adding hoops, and you forgot to update the docs?
Or is it a regression?

@tennox
Copy link
Contributor Author

tennox commented Mar 3, 2025

While we're at it - I'm not quite grokking the concept of a Service - and it's not really mentioned in the docs book... Only section I found was this: https://salvo.rs/book/concepts/handler.html#what-is-handler - and that is only confusing me more, to be honest.

chrislearn pushed a commit that referenced this issue Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants