From bca3ab5eb63db48d95e4c34609bf564a4c942862 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Fri, 1 Sep 2023 16:20:49 +0100 Subject: [PATCH] Add CORS headers for /graphql --- crates/handlers/src/lib.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/handlers/src/lib.rs b/crates/handlers/src/lib.rs index 9fc65f4a..b22cc971 100644 --- a/crates/handlers/src/lib.rs +++ b/crates/handlers/src/lib.rs @@ -116,10 +116,23 @@ where Encrypter: FromRef, CookieJar: FromRequestParts, { - let mut router = Router::new().route( - "/graphql", - get(self::graphql::get).post(self::graphql::post), - ); + let mut router = Router::new() + .route( + "/graphql", + get(self::graphql::get).post(self::graphql::post), + ) + .layer( + CorsLayer::new() + .allow_origin(Any) + .allow_methods(Any) + .allow_otel_headers([ + AUTHORIZATION, + ACCEPT, + ACCEPT_LANGUAGE, + CONTENT_LANGUAGE, + CONTENT_TYPE, + ]), + ); if playground { router = router.route("/graphql/playground", get(self::graphql::playground));