-
Notifications
You must be signed in to change notification settings - Fork 641
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
GraphQL: CORS #4830
Comments
Thanks for bringing that up. We just released Craft 3.3.0.1 which automatically sets the appropriate CORS headers to allow crossdomain API requests. |
I'm still having this issue on 3.3.0.1 as well. |
Hm strange, the cms/src/controllers/GraphqlController.php Line 71 in 069f389
|
Could it not be using the port? CORS is port specific. |
Are you able to view the |
I'm in the same scenario as @kjbrum. I'll get it set back up and provide more details later today. |
If either of you know which headers we should be adding to actionApi(), let me know or submit a PR and we will get them in. |
Getting the following error in 3.3.0.1
So adding /sh |
@wsydney76, removing content type from your request fixes this. @brandonkelly I was able to get everything working fine this go around. Not sure what changed except maybe removing the content type from my request. |
In addition to |
@wsydney76 Craft is allowing the @gregorterrill The
cms/src/controllers/GraphqlController.php Line 72 in 069f389
|
Brandon! Hope you've been well. I am actually encountering this as well on I checked Any reason to not just allow I'm not sure it's any less secure than injecting the request origin -- but comes with the benefit of allowing any port (which in my local dev i'm on something random). Thanks! |
Dang it! It was my fault... I totally forgot to add the URI that I exposed GraphQL under and was pointing to the root domain. Ignore me! 😜 |
Good to hear from you @rkingon :) Glad you got this sorted. |
I had similar issues when suddenly my local nuxt app was serving not under Now my question is: where in my craft installation is the crucial part, where I allow the graphql API to return values to Cheers |
@Jones-S That is a server configuration thing, not a Craft setting. |
@brandonkelly Thank you for your answer. Do you have a suspicion where I would have to change a setting in my MAMP, to allow not only |
@Jones-S Not sure how much control regular MAMP will give you over that; I’d suggest upgrading to MAMP Pro, which will let you set up multiple local hosts each with their own host names (e.g. |
I do have MAMP Pro, but still I would not know where to start looking for the right settings. |
@Jones-S Laravel Valet is an amazing tool for local development as well. |
@Jones-S to be clear I was referring to Laravel Homestead (or just “Homestead” for short), which is a local development environment powered by Vagrant. Laravel itself is an application framework, that is separate from Homestead. (Same goes for Laravel Valet as @kjbrum suggested – though I wouldn’t necessarily recommend that; a lot of people have struggled getting that working properly.) |
docker ftw! =D |
Hi Brandon, sorry to bring this one back to life -- I just started using GraphQL on an older project that is using a stock heroku php buildpack, and the way the server is setup, heroku seems to be passing two origins up via headers, which is causing the cors config in Right now,
A tiny bit of looking online says if you're going to stuff in the origin, try and detect if multiple origins (comma separated) and only use the first one. However, I think a better solution would be to just sub out |
@rkingon Yeah I agree. Just changed it to To get the fix early, change your "require": {
"craftcms/cms": "dev-develop#a9e07bf9d1eb65c1fd9f6c1ed76ada349a705687 as 3.4.15",
"...": "..."
} Then run |
Awesome- thank you, Brandon! Super helpful. (now I get to delete the reverse proxy I created this morning to get it onto the same domain =D) |
Craft 3.4.16 is out now with that change. |
Craft 3 already sets this header, so setting it again was throwing a "multiple headers" error in the browser: craftcms/cms#4830
Craft 3 already sets this header, so setting it again was throwing a "multiple headers" error in the browser: craftcms/cms#4830
Description
The documentation for the GraphQL api doesn't specify a way to seat CORS headers. How would you do that?
Steps to reproduce
Additional info
The text was updated successfully, but these errors were encountered: