Skip to content

Commit

Permalink
move CORS fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
lucat1 committed Dec 28, 2023
1 parent 8f55b35 commit 39cf1ad
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ pub mod jsonapi;
mod tempo;

use axum::{
http::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
http::{
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
Method,
},
Router,
};
use base::database::get_database;
pub use error::Error;
use eyre::Result;
use sea_orm::DbConn;
use tower_http::{
cors::{AllowOrigin, Any, CorsLayer},
cors::{AllowOrigin, CorsLayer},
trace::TraceLayer,
};

Expand All @@ -24,8 +27,16 @@ pub struct AppState(pub DbConn);

pub fn router() -> Result<Router> {
let cors = CorsLayer::new()
.allow_methods(Any)
.allow_methods([
Method::OPTIONS,
Method::HEAD,
Method::GET,
Method::POST,
Method::PUT,
Method::PATCH,
])
.allow_origin(AllowOrigin::mirror_request())
.allow_credentials(true)
.allow_headers([AUTHORIZATION, ACCEPT, CONTENT_TYPE]);
let tracing = TraceLayer::new_for_http();
let conn = get_database()?.clone();
Expand Down

0 comments on commit 39cf1ad

Please sign in to comment.