From 7c492396257462f96aba047febf3168f8ec2524e Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 29 Aug 2024 17:23:59 +0200 Subject: Add CORS --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/main.rs') 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)) } -- cgit v1.2.3-18-g5258