diff options
author | Santo Cariotti <santo@dcariotti.me> | 2022-11-21 08:43:07 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2022-11-21 11:14:53 +0100 |
commit | 7d661b657bbc31062e90b1a9c2bd8666627c2e07 (patch) | |
tree | a2576da3ca2f548f8bc753e5e5e4d99c1bf88795 /server/src | |
parent | ed6e98137754f168480e0700063b01f14dd4f240 (diff) |
Add CORS rules
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/main.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 4a211fd..7da56d6 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -5,12 +5,16 @@ mod models; mod routes; use axum::{ - http::{header, Request}, + http::{header, Method, Request}, Router, }; use std::time::Duration; -use tower_http::sensitive_headers::SetSensitiveHeadersLayer; -use tower_http::{classify::ServerErrorsFailureClass, trace::TraceLayer}; +use tower_http::{ + classify::ServerErrorsFailureClass, + cors::{Any, CorsLayer}, + sensitive_headers::SetSensitiveHeadersLayer, + trace::TraceLayer, +}; use tracing::Span; /// Main application, called by the execution of the software @@ -57,4 +61,16 @@ async fn create_app() -> Router { }, ), ) + .layer( + CorsLayer::new() + .allow_methods([ + Method::OPTIONS, + Method::GET, + Method::POST, + Method::PUT, + Method::DELETE, + ]) + .allow_headers(vec![header::CONTENT_TYPE, header::AUTHORIZATION]) + .allow_origin(Any), + ) } |