summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-08-29 17:23:59 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-08-29 17:23:59 +0200
commit7c492396257462f96aba047febf3168f8ec2524e (patch)
tree064bc7d7f9d5085f73eb6cc1c805adfe5735a905 /src
parent776e61237601236fb1ad68f4047cca40263acf23 (diff)
Add CORS
Diffstat (limited to 'src')
-rw-r--r--src/main.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e53395a..1614e6b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,13 +11,15 @@ use std::{net::SocketAddr, sync::Arc, time::Duration};
use crate::config::CONFIG;
use async_graphql::{EmptySubscription, Schema};
use axum::{
- http::{header, Request},
+ http::{header, Method, Request},
routing::post,
Extension, Router,
};
use tokio::net::TcpListener;
use tower_http::{
- classify::ServerErrorsFailureClass, sensitive_headers::SetSensitiveHeadersLayer,
+ classify::ServerErrorsFailureClass,
+ cors::{Any, CorsLayer},
+ sensitive_headers::SetSensitiveHeadersLayer,
trace::TraceLayer,
};
@@ -63,6 +65,12 @@ async fn create_app() -> Router {
},
),
)
+ .layer(
+ CorsLayer::new()
+ .allow_methods([Method::OPTIONS, Method::GET, Method::POST])
+ .allow_headers(vec![header::CONTENT_TYPE, header::AUTHORIZATION])
+ .allow_origin(Any),
+ )
.layer(Extension(state))
}