@@ -21,19 +21,20 @@ use std::{
21
21
22
22
use axum:: {
23
23
body:: Body ,
24
+ http:: Method ,
24
25
response:: Response ,
25
26
routing:: { get, on, MethodFilter } ,
26
27
Extension , Router ,
27
28
} ;
28
29
30
+ use crate :: { cache:: Multithreaded , fetch:: make_client} ;
29
31
use juniper:: { graphql_object, EmptyMutation , EmptySubscription , RootNode } ;
30
32
use juniper_axum:: { graphiql, graphql, playground, ws} ;
31
33
use juniper_graphql_ws:: ConnectionConfig ;
32
34
use parse:: Locations ;
33
35
use 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 } ;
37
38
38
39
#[ derive( Clone , Copy , Debug ) ]
39
40
pub struct Query ;
@@ -94,6 +95,9 @@ async fn main() {
94
95
. deflate ( true )
95
96
. gzip ( true )
96
97
. zstd ( true ) ;
98
+ let cors_layer = CorsLayer :: new ( )
99
+ . allow_methods ( [ Method :: GET , Method :: POST ] ) // intentionally excludes request-refresh/PUT
100
+ . allow_origin ( Any ) ;
97
101
pretty_env_logger:: init ( ) ;
98
102
99
103
let app = Router :: new ( )
@@ -111,6 +115,7 @@ async fn main() {
111
115
. route ( "/request-refresh" , on ( MethodFilter :: PUT , refresh) )
112
116
. route ( "/graphiql" , get ( graphiql ( "/graphql" , "/subscriptions" ) ) )
113
117
. route ( "/playground" , get ( playground ( "/graphql" , "/subscriptions" ) ) )
118
+ . layer ( cors_layer)
114
119
. layer ( Extension ( Arc :: new ( schema) ) )
115
120
. layer ( comression_layer) ;
116
121
tokio:: spawn ( async move {
0 commit comments