Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit bca3ab5

Browse files
hughnssandhose
authored andcommitted
Add CORS headers for /graphql
1 parent a01c530 commit bca3ab5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

crates/handlers/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,23 @@ where
116116
Encrypter: FromRef<S>,
117117
CookieJar: FromRequestParts<S>,
118118
{
119-
let mut router = Router::new().route(
120-
"/graphql",
121-
get(self::graphql::get).post(self::graphql::post),
122-
);
119+
let mut router = Router::new()
120+
.route(
121+
"/graphql",
122+
get(self::graphql::get).post(self::graphql::post),
123+
)
124+
.layer(
125+
CorsLayer::new()
126+
.allow_origin(Any)
127+
.allow_methods(Any)
128+
.allow_otel_headers([
129+
AUTHORIZATION,
130+
ACCEPT,
131+
ACCEPT_LANGUAGE,
132+
CONTENT_LANGUAGE,
133+
CONTENT_TYPE,
134+
]),
135+
);
123136

124137
if playground {
125138
router = router.route("/graphql/playground", get(self::graphql::playground));

0 commit comments

Comments
 (0)