andreas / ocaml-graphql-server

GraphQL servers in OCaml
MIT License
622 stars 60 forks source link

make_callback does not support preflight requests for CORS #187

Open emillon opened 4 years ago

emillon commented 4 years ago

Hi,

When the client is on a different origin than the server, the client sends a preflight OPTIONS request to OGS, which returns a 404:

https://github.com/andreas/ocaml-graphql-server/blob/940e86f9ff1a017be2ff64b3a35c71804d9a4729/graphql-cohttp/src/graphql_cohttp.ml#L188

That prevents directly using make_callback in this scenario.

What do you think about adding a ?allowed_origins optional parameter that adds the right handler to OPTIONS /graphql? I'm happy to provide a patch.

Thanks!

andreas commented 4 years ago

Yes, that would be great 😄