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

Access to fetch has been blocked by CORS policy #340

Open
pedroandradef opened this issue Nov 18, 2020 · 1 comment
Open

Access to fetch has been blocked by CORS policy #340

pedroandradef opened this issue Nov 18, 2020 · 1 comment

Comments

@pedroandradef
Copy link

Im using Apollo with Graphql Code Generator to do some queries but all responses has been blocked. Its just to learn so no envs there.
Screen Shot 2020-11-18 at 3 46 42 PM
Screen Shot 2020-11-18 at 3 46 32 PM
Screen Shot 2020-11-18 at 5 22 03 PM

@maxfrischknecht
Copy link

You need to address this issue on the server side rather than the client side.
Add the following code to the bottom of the .htaccess in the /web folder:

<ifModule mod_headers.c>
  Header always set Access-Control-Allow-Origin "*"
  Header always set Access-Control-Allow-Headers "accept,authorization,content-type,origin,x-auth-token"
  Header always set Access-Control-Allow-Methods "PUT,POST,GET,OPTIONS,ORIGIN"
</ifModule>

It is not recommended to use Header always set Access-Control-Allow-Origin "*"from a security perspective. So rather use the direct domain from where your frontend will be calling the api when you are ready for production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants