Support CORS enabled servers and OPTIONS requests
See original GitHub issue // GraphQL HTTP only supports GET and POST methods.
if (request.method !== 'GET' && request.method !== 'POST') {
response.set('Allow', 'GET, POST');
return sendError(
response,
httpError(405, 'GraphQL only supports GET and POST requests.'),
pretty
);
}
Currently if the Express app enables CORS express-graphql
will fail due to the above check sending a 405
error when the OPTIONS
request comes in.
Two options I see:
- Create a flag for enabling CORS in
express-graphql
and enableOPTION
support whentrue
- Just support
OPTION
requests by default
I’d be happy to implement either, or another option, pending approval!
Issue Analytics
- State:
- Created 8 years ago
- Comments:37 (7 by maintainers)
Top Results From Across the Web
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
The CORS mechanism supports secure cross-origin requests and data transfers between browsers and servers. Modern browsers use CORS in APIs ...
Read more >CORS Enabled - W3C Wiki
CORS can be enabled using the Headers core module which is compiled into nginx by default: ... Set the CORS options on your...
Read more >Enabling CORS for a REST API resource - Amazon API Gateway
For a mock integration, you enable CORS by creating an OPTIONS method to return the required response headers (with appropriate static values) as...
Read more >CORS Support - MockServer
By default, CORS support is not enabled for the Control Plane API and or for mocked response, such as, when expectations are matched,...
Read more >CORS Tutorial: A Guide to Cross-Origin Resource Sharing
When a server has been configured correctly to allow cross-origin resource sharing, some special headers will be included. Their presence can be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, I got CORS working for my needs. Here’s a full(ish) example for anyone else who stumbles upon this:
A simple way without use of the
cors
module: