Skip to content

Commit 39cf1ad

Browse files
committed
move CORS fixing
1 parent 8f55b35 commit 39cf1ad

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

server/src/api/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ pub mod jsonapi;
77
mod tempo;
88

99
use axum::{
10-
http::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
10+
http::{
11+
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
12+
Method,
13+
},
1114
Router,
1215
};
1316
use base::database::get_database;
1417
pub use error::Error;
1518
use eyre::Result;
1619
use sea_orm::DbConn;
1720
use tower_http::{
18-
cors::{AllowOrigin, Any, CorsLayer},
21+
cors::{AllowOrigin, CorsLayer},
1922
trace::TraceLayer,
2023
};
2124

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

2528
pub fn router() -> Result<Router> {
2629
let cors = CorsLayer::new()
27-
.allow_methods(Any)
30+
.allow_methods([
31+
Method::OPTIONS,
32+
Method::HEAD,
33+
Method::GET,
34+
Method::POST,
35+
Method::PUT,
36+
Method::PATCH,
37+
])
2838
.allow_origin(AllowOrigin::mirror_request())
39+
.allow_credentials(true)
2940
.allow_headers([AUTHORIZATION, ACCEPT, CONTENT_TYPE]);
3041
let tracing = TraceLayer::new_for_http();
3142
let conn = get_database()?.clone();

0 commit comments

Comments
 (0)