Hello! I was working with strawberry-graphql[channels], a graphql server based on django channels.
In the meantime, I needed a cors library that supports asgi, so I used asgi_cors.
If the client requests a query to the server to get a response,
Is there any way other than directly modifying asgi_cors.py?
# asgi_cors.py
...
if access_control_allow_origin is not None:
status = 200 if scope["method"] == "OPTIONS" else event["status"] ####################
event = {
"type": "http.response.start",
"status": status,
"headers": [ p for p in original_headers if p[0] != b"access-control-allow-origin"]
+ [
[ b"access-control-allow-origin", access_control_allow_origin],
[ b"access-control-allow-headers", b"Content-Type"] ####################
],
}
await send(event)
added lines
- add for preflight method OPTIONS, if i don't add then event["status"] is 405
- add access-control-allow-headers, if i don't add then get error because in request, gql is sent
I met each and every problem about cors in my situation and managed to solve it.
But I'm not sure if this is the right solution and I'm asking to see if there is a better way.
Actually, I don't know if I can post this on Issues.
If it's a problem, I'll delete it.
Thanks for reading the long article.