@@ -21,19 +21,20 @@ use std::{
2121
2222use axum:: {
2323 body:: Body ,
24+ http:: Method ,
2425 response:: Response ,
2526 routing:: { get, on, MethodFilter } ,
2627 Extension , Router ,
2728} ;
2829
30+ use crate :: { cache:: Multithreaded , fetch:: make_client} ;
2931use juniper:: { graphql_object, EmptyMutation , EmptySubscription , RootNode } ;
3032use juniper_axum:: { graphiql, graphql, playground, ws} ;
3133use juniper_graphql_ws:: ConnectionConfig ;
3234use parse:: Locations ;
3335use tokio:: { net:: TcpListener , sync:: OnceCell , time:: sleep} ;
34- use tower_http:: compression:: CompressionLayer ;
35-
36- use crate :: { cache:: Multithreaded , fetch:: make_client} ;
36+ use tower_http:: cors:: CorsLayer ;
37+ use tower_http:: { compression:: CompressionLayer , cors:: Any } ;
3738
3839#[ derive( Clone , Copy , Debug ) ]
3940pub struct Query ;
@@ -94,6 +95,9 @@ async fn main() {
9495 . deflate ( true )
9596 . gzip ( true )
9697 . zstd ( true ) ;
98+ let cors_layer = CorsLayer :: new ( )
99+ . allow_methods ( [ Method :: GET , Method :: POST ] ) // intentionally excludes request-refresh/PUT
100+ . allow_origin ( Any ) ;
97101 pretty_env_logger:: init ( ) ;
98102
99103 let app = Router :: new ( )
@@ -111,6 +115,7 @@ async fn main() {
111115 . route ( "/request-refresh" , on ( MethodFilter :: PUT , refresh) )
112116 . route ( "/graphiql" , get ( graphiql ( "/graphql" , "/subscriptions" ) ) )
113117 . route ( "/playground" , get ( playground ( "/graphql" , "/subscriptions" ) ) )
118+ . layer ( cors_layer)
114119 . layer ( Extension ( Arc :: new ( schema) ) )
115120 . layer ( comression_layer) ;
116121 tokio:: spawn ( async move {
0 commit comments