Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS not working on apollo-server-express #3058

Closed
avocadoslab opened this issue Jul 19, 2019 · 1 comment
Closed

CORS not working on apollo-server-express #3058

avocadoslab opened this issue Jul 19, 2019 · 1 comment

Comments

@avocadoslab
Copy link
Contributor

avocadoslab commented Jul 19, 2019

Package: apollo-server-express

Version: v2.6.0

Issue: CORS settings aren't taking effect.

Description: From our react client, we started sending apollographql-client-name & apollographql-client-version headers for better client awareness in Apollo Engine.

Access to fetch at 'https://something.com/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field apollographql-client-name is not allowed by Access-Control-Allow-Headers in preflight response.

We receive following above CORS error. We enabled cors on Apollo Server through express middleware by passing cors: true. For some reason, this changes are not making any difference. We continue to receive above error.

const server: ApolloServer = new ApolloServer({
...
...
});

const app: Application = express();

server.applyMiddleware({
   app,
   cors: true,
   path: '/graphql',
});
  • We have nginx sitting in front and it does receive request and forwards to Apollo Server.
  • cors: true enables everything by default?
  • We tried being very specific but that didn't help either.
cors: {
   origin: true,
   allowedHeaders: ['Authorization', 'Content-Type', 'apollographql-client-name']
},

Any inputs and suggestions are welcome!

@avocadoslab
Copy link
Contributor Author

avocadoslab commented Jul 20, 2019

We figured out the root cause.

We had kubernetes ingress layer on top of our Apollo Server and that's what was causing changes not to reflect. After we enabled cors on nginx ingress, we were able to make successful calls.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant