allow content-type through CORS

This commit is contained in:
41666 2022-11-27 23:12:37 -05:00
parent 07b3af9166
commit 3c6b89b152

View file

@ -11,13 +11,13 @@ use async_graphql::{
}; };
use axum::{ use axum::{
extract::Query, extract::Query,
http::Method, http::{header::CONTENT_TYPE, Method},
response::{Html, IntoResponse, Redirect}, response::{Html, IntoResponse, Redirect},
routing::{get, post}, routing::{get, post},
Extension, Json, Router, Extension, Json, Router,
}; };
use std::net::SocketAddr; use std::net::SocketAddr;
use tower_http::cors::{Any, CorsLayer}; use tower_http::cors::{AllowHeaders, Any, CorsLayer};
#[macro_use] #[macro_use]
extern crate serde_json; extern crate serde_json;
@ -80,11 +80,12 @@ async fn main() {
.fallback(handle_404) .fallback(handle_404)
.layer(Extension(redis)) .layer(Extension(redis))
.layer(Extension(schema)) .layer(Extension(schema))
.layer(CorsLayer::new().allow_origin(Any).allow_methods([ .layer(
Method::GET, CorsLayer::new()
Method::POST, .allow_origin(Any)
Method::OPTIONS, .allow_headers([CONTENT_TYPE])
])); .allow_methods([Method::GET, Method::POST, Method::OPTIONS]),
);
let port: u16 = std::env::var("PORT") let port: u16 = std::env::var("PORT")
.unwrap_or("8000".to_string()) .unwrap_or("8000".to_string())