CORS error when using new docker-compose setup

I’m using the docker-compose config at dgraph/docker-compose.yml at master · dgraph-io/dgraph · GitHub to bring up dgraph.

When using apollo-client in my browser, and pointing it to http://localhost:8080/graphql i get the following error:
Access to fetch at 'http://localhost:8080/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field username is not allowed by Access-Control-Allow-Headers in preflight response.

How do i configure dgraph to provide CORS headers?

I am not sure how to fix this. But as a workaround you can install Allow CORS: Access-Control-Allow-Origin extension for chrome and enable it. Similar extension for other browsers.

cc: @vardhanapoorv if he knows the fix.

1 Like

Hi, Another fellow user here, Yes there is no workaround as such for that. Google and Firefox both have included this as security fix

You have options such as disabling this using Chrome Extensions as mentioned above. However if you make same requests using curl or code client that should work.

1 Like

What are you passing in the username header? AFAIK, that’s not a standard header that dgraph accepts?