Skip to content

Commit

Permalink
Fix CORS issue in GraphQL example that prevented Apollo Studio from w…
Browse files Browse the repository at this point in the history
…orking (#27486)

Update example so Apollo Studio works properly
  • Loading branch information
Mahmoud Abdelwahab authored Jul 25, 2021
1 parent 84b71c3 commit f657e09
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/api-routes-graphql/pages/api/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ const apolloServer = new ApolloServer({ typeDefs, resolvers })
const startServer = apolloServer.start()

export default async function handler(req, res) {
if (req.method === 'OPTIONS') {
res.end()
return false
}
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader(
'Access-Control-Allow-Origin',
'https://studio.apollographql.com'
)
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
)
if (req.method === 'OPTIONS') {
res.end()
return false
}

await startServer
await apolloServer.createHandler({
Expand Down

1 comment on commit f657e09

@abdulmatinshah
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If authorization header is passed then response ends, any solution to that

Please sign in to comment.