From 16b89f9a7206069a9621e14b6d99e98e79f9e306 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Sun, 20 Oct 2024 11:21:47 +0200 Subject: [PATCH 1/2] add cors headers for preflight requests --- agdb_server/Cargo.toml | 1 + agdb_server/src/app.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/agdb_server/Cargo.toml b/agdb_server/Cargo.toml index f7f05e3f4..446d527fb 100644 --- a/agdb_server/Cargo.toml +++ b/agdb_server/Cargo.toml @@ -24,6 +24,7 @@ serde_json = "1" serde_yaml = "0.9" tokio = { version = "1", features = ["full"] } tower = "0.4" +tower-http = { version = "0.6", features = ["cors"] } tracing = "0.1" tracing-subscriber = "0.3" url = { version = "2", features = ["serde"] } diff --git a/agdb_server/src/app.rs b/agdb_server/src/app.rs index 8f95db561..91a419cfb 100644 --- a/agdb_server/src/app.rs +++ b/agdb_server/src/app.rs @@ -8,7 +8,9 @@ use crate::server_state::ServerState; use axum::middleware; use axum::routing; use axum::Router; +use reqwest::Method; use tokio::sync::broadcast::Sender; +use tower_http::cors::CorsLayer; use utoipa::OpenApi; use utoipa_rapidoc::RapiDoc; @@ -142,6 +144,10 @@ pub(crate) fn app( routing::put(routes::user::change_password), ); + let cors = CorsLayer::new() + .allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE]) + .allow_origin(tower_http::cors::Any); + let router = Router::new() .merge(RapiDoc::with_openapi("/api/v1/openapi.json", Api::openapi()).path("/api/v1")) .nest("/api/v1", api_v1) @@ -149,6 +155,7 @@ pub(crate) fn app( state.clone(), logger::logger, )) + .layer(cors) .with_state(state); if !basepath.is_empty() { From 9523c8cbcbc9e709d26c19dd2813e07fa6bb4694 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Sun, 20 Oct 2024 11:27:23 +0200 Subject: [PATCH 2/2] fix clippy --- agdb/src/query.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/agdb/src/query.rs b/agdb/src/query.rs index 19decc956..bdc4b7039 100644 --- a/agdb/src/query.rs +++ b/agdb/src/query.rs @@ -57,6 +57,7 @@ use crate::{ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] #[derive(Debug, PartialEq)] +#[expect(clippy::large_enum_variant)] pub enum QueryType { InsertAlias(InsertAliasesQuery), InsertEdges(InsertEdgesQuery),