helpful note about posting with CORS (#938)

This commit is contained in:
Slava 2022-04-17 11:13:22 +03:00 committed by GitHub
parent bef7700fcf
commit 0313c08dc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,10 @@ async fn main() {
let app = Router::new().route("/json", get(json)).layer(
// see https://docs.rs/tower-http/latest/tower_http/cors/index.html
// for more details
//
// pay attention that for some request types like posting content-type: application/json
// it is required to add ".allow_headers(vec![http::header::CONTENT_TYPE])"
// or see this issue https://github.com/tokio-rs/axum/issues/849
CorsLayer::new()
.allow_origin(Origin::exact("http://localhost:3000".parse().unwrap()))
.allow_methods(vec![Method::GET]),