-
Notifications
You must be signed in to change notification settings - Fork 0
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
CORS support? #1
Comments
I have to release more.cors. But it's actually ready so I can release today. |
@henri-hulski Yes! It is working nicely now. Thank you very much. |
@henri-hulski Hum... Actually something is wrong. All routes appear to work, except
which returns 404 and no CORS headers. This makes impossible to update the user profile, because the browser rejects to do the PUT if the preflight response is not successful. I think the problem can be related to the fact that the browser does not send the Authorization token as part of the preflight. Somehow, This is the request:
This is the answer:
|
Thanks for checking this |
@jldiaz Could you open an issue in more.cors as it seems to belong there. |
I do not really understand why the route to |
No, it is not a cache problem. I have the same results if I perform the queries from CLI, using Apparently, the browser never sends the Authentication header as part of OPTIONS, so any route which requires authentication (and should produce 401 if no auth is provided), causes a 404 error instead. Routes which are not protected, such as Interestinlgy, it is even posible to create a new article, because that is a POST on /api/articles, and this route allows GET (and thus OPTIONS) without auth. |
If you adjust the |
For example by adding to cors:
allowed_origin: https://conduit.yacoma.it
allow_credentials: True |
No luck. Still the preflight answer does not contain cors headers. I think the problem is related to line 94 in more.cors/main.py, because when the model is (tried to be) resolved, the exception I think that causes trouble later, when at line 117 the context is used to find out the allowed verbs. The However I think that is a "philosophical" design flaw, difficult to be solved. I can build a (not so) minimal example using morepath, more.cors and more.jwt to show the problem, and post it as an issue at more.cors. |
I'm not sure if more.cors is to be blamed... The problem is caused in fact by this line in The problem is solved if permissions are managed in a standard way, i.e: allowing the path to return the appropiate model, and leaving the permission management to the view. I discovered this in the minimal app I was preparing to illustrate the issue. |
Hmm but that line should raise a |
If the path returns |
In more.cors this line is raising a 404 exception: |
The true problem is not wheter more.cors returns 401 or 404. The real problem is that the CORS headers are absent from the response (because not allowed-methods were found). Thus, when the browser receives this response, it aborts the request. To summarize:
A solution could be to modify more.cors so that it returns |
Ok I got it. Thanks for the explanation. BTW As it seems you are into the CORS thingy maybe you could also review morepath/more.cors#2. A haven't found anyone who wanted to review it and at the end just merged it in. It looks good to me, but I'm not too experienced with CORS. |
Fixed in morepath/more.cors#4. |
Hello.
Thank you very much for the effort of putting together this real-world example code. I was working on a project which uses morepath+pony at the backend and your example provides invaluable info for the configuration and deployment.
However, as far as I can see, your backend does not support CORS. When I try, for example, the Angular client and set https://conduit.yacoma.it/api as the
api_url
inenvironments/environment.ts
, the page shows "Loading articles..." and no progress happens.If I deploy my own local server (in a machine different than the one serving the client), I can see that the browser is sending OPTIONS requests (the CORS preflight), and the backend is answering "405 Method not allowed", instead of answering with "200 OK" and the appropiate CORS headers.
In my own project I had this problem also, and solved it by adding somewhere (in
views.py
) the following snippet:But I'm not sure if this is the proprer way to do it in "real world".
Could you please provide an example showing how CORS can be added to the backend?
The text was updated successfully, but these errors were encountered: