@@ -5,13 +5,27 @@ const setCors = require('./utils/setCors')
5
5
const graphQLOptions = {
6
6
// Set the path for the GraphQL server
7
7
baseEndpoint : '/' ,
8
+
8
9
// Set the path for the GraphQL playground
9
10
// This option can be removed to disable the playground route
10
11
playgroundEndpoint : '/___graphql' ,
12
+
11
13
// When a request's path isn't matched, forward it to the origin
12
14
forwardUnmatchedRequestsToOrigin : false ,
15
+
13
16
// Enable debug mode to return script errors directly in browser
14
17
debug : false ,
18
+
19
+ // Enable CORS headers on GraphQL requests
20
+ // Set to `true` for defaults (see `utils/setCors`),
21
+ // or pass an object to configure each header
22
+ cors : true ,
23
+ // cors: {
24
+ // allowCredentials: 'true',
25
+ // allowHeaders: 'Content-type',
26
+ // allowOrigin: '*',
27
+ // allowMethods: 'GET, POST, PUT',
28
+ // },
15
29
}
16
30
17
31
const handleRequest = request => {
@@ -22,7 +36,9 @@ const handleRequest = request => {
22
36
request . method === 'OPTIONS'
23
37
? new Response ( '' , { status : 204 } )
24
38
: await apollo ( request , graphQLOptions )
25
- setCorsHeaders ( response )
39
+ if ( graphQLOptions . cors ) {
40
+ setCors ( response , graphQLOptions . cors )
41
+ }
26
42
return response
27
43
} else if (
28
44
graphQLOptions . playgroundEndpoint &&
0 commit comments