-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
How to configure CORS? #234
Comments
Fixed by adding a cors bypass middleware: let cors_middleware inner_handler req =
let new_headers =
[
("Allow", "OPTIONS, GET, HEAD, POST");
("Access-Control-Allow-Origin", "*");
("Access-Control-Allow-Headers", "*");
]
in
let+ response = inner_handler req in
new_headers
|> List.map (fun (key, value) -> Dream.add_header response key value)
|> ignore;
response and an Dream.options "/graphql" (fun _req ->
Dream.respond ~headers:[ ("Allow", "OPTIONS, GET, HEAD, POST") ] ""); Of course, I need to change the allowed origin when changing to production. |
Thank you. I made similar middleware too: let cors_middleware handler req =
let handlers =
[ "Allow", "OPTIONS, GET, HEAD, POST"
; "Access-Control-Allow-Origin", "*"
; "Access-Control-Allow-Methods", "OPTIONS, GET, HEAD, POST"
; "Access-Control-Allow-Headers", "Content-Type"
; "Access-Control-Max-Age", "86400"
]
in
let%lwt res = handler req in
handlers
|> List.map (fun (key, value) -> Dream.add_header res key value)
|> ignore;
Lwt.return res |
Thank you! CORS is something that is probably best handled by Dream by offering an example. It's actually in the examples roadmap, but I haven't had time to create it yet. If some really common patterns emerge, maybe something is worth merging into Dream code. |
I'm getting the following error while using Dream.graphql it with a frontend React app (running in a different port):
The text was updated successfully, but these errors were encountered: