How do I configure Apollo Server to accept custom headers?

Have more questions? Submit a request

When running Apollo Server in production mode, you might experience an issue where custom HTTP headers aren't accessible to your code.

This is due to CORS security settings. To allow headers besides the standard set of request headers (authorization, content-type, etc.), you need to add them to the allowedHeaders property of your Apollo Server configuration.

This property can take either a string or an array of strings:

  const server: ApolloServer = new ApolloServer({
    schema,
    dataSources,
    cors: {
      allowedHeaders: ["customHeader1", "customHeader2"],
      ...other cors settings
    },
  });

For a full tutorial on CORS configuration in Apollo Server, please see our docs.

Articles in this section

Was this article helpful?
0 out of 0 found this helpful
Share

Comments

0 comments

Please sign in to leave a comment.