-
Notifications
You must be signed in to change notification settings - Fork 61
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
Make CORS configurable #66
Comments
First draft of patch for this issue is up on my fork https://github.com/PapaBearNZ/silverstripe-graphql Patch adds Yaml config for CORS to the graphql module. Also adds a check for the pre-flight OPTIONS request, and if CORS is enabled, adds the appropriate headers to the response object - both for the OPTIONS response and for the actual data response. No unit tests as yet. Looking for suggestions and comments on improvements. One concern is the 301 redirect from SS to get around the fact that the module folder and the graphql endpoint are the same name. This redirect breaks CORS pre-flight. I suggest that the module folder be renamed to |
Looks great :) A few comments:
I've fixed the 301 redirect, see silverstripe/silverstripe-installer#152 |
Thanks Ingo. Regarding the allow headers . I think we still need the OPTIONS method as well. Otherwise won't the request bounce? Understood about the YAML default config and I agree with the suggestion of defaulting to denied rather than open. I used '*' because that's what the REST module used but denied is a safer default. I'll make the appropriate changes and hopefully have a PR ready later today. Thanks for the work on the redirect issue. I'll update and test that. Regarding the README - no problem there. However, the docs are getting pretty big. Is this going to be updated and pushed to docs/en? |
Added getCorsResponse() to GraphQL to detect a CORS preflight OPTIONS request and append the correct headers. Also checks the origin is an allowed domain for cross-origin requests. Included unittests for invalid origin, valid origin, OPTIONS request type.
#69 PR submitted. |
Added getCorsResponse() to GraphQL to detect a CORS preflight OPTIONS request and append the correct headers. Also checks the origin is an allowed domain for cross-origin requests. Included unittests for invalid origin, valid origin, OPTIONS request type.
* Added addCorsHeaders() function to append appropriate headers to response if necessary. * Added cors section to SilverStripe\GraphQL config object. * Added UnitTests. * Added README documentation for CORS handling.
* Added addCorsHeaders() function to append appropriate headers to response if necessary. * Added cors section to SilverStripe\GraphQL config object. * Added UnitTests. * Added README documentation for CORS handling.
Looks like this was fixed with #69 not sure why it's still open. |
GraphQL APIs will be consumed by third party apps on other hosts, e.g. sending XHR requests from your custom web app to a centralised SaaS solution running a SilverStripe-powered GraphQL endpoint. This requires Cross Origin Resource Sharing
See https://github.com/colymba/silverstripe-restfulapi/blob/master/doc/RESTfulAPI.md#cors for an example.
The text was updated successfully, but these errors were encountered: