-
Notifications
You must be signed in to change notification settings - Fork 140
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
Getting CORS preflight error even with flask cors initialized #292
Comments
@ryanbrwr did you find any solution? |
@shrhawk-entertainer No unfortunately I never found a solution and I am currently having to develop with CORS disabled in safari to get around this. |
@ryanbrwr Does your OPTIONS call to server return 200 OK? |
I gave up a long time ago and used a different lib, appreciate it though. |
@ryanbrwr what lib did you used ? |
@Elynad did you implement the |
@cohi-dev Yes, I did Here is a part of my code :
I also tried to replace And I also tried to add The thing is, everything is working fine in local (I am using dockers), but when these dockers are deployed on AWS EC2 instance, I get an XMLHttpRequest error 😕 |
Check network tab in browser and check preflight response paste it here. |
@Elynad what I did is
|
@shrhawk-entertainer It seems to be a good answer, but where do you get |
You import it from flask module. Check documentation on how it works if you want to know how it works. |
Right. Does not seems to work, I will make some tests this friday to keep you in touch |
What do you mean by does not work. Do you have it registered in right blueprint. Have you tried breakpoint in that before request? Preflight request must return correct headers and respond with status 200. |
Preflight request did return status 200. But the original request does not seems to work, and I get nothing in the "Response" tab when I click on the request. As I am testing a production deployment, I can't breakpoint, but I am writing in a
The |
@Elynad I'd suggest that you use the logging functionality provided by flask to do this logging. |
I think the best way to avoid this issue is add more rule for url like. from werkzeug.routing import Rule
app = Flask(__name__, static_url_path='/static')
app.url_rule_class = lambda path, **options: Rule(
app.static_url_path + path, **options
) |
Did someone find some solution? It really sucks..... |
This worked brilliantly for me: #292 (comment) |
Wow. This works for me too. Effectively returning a 200 on OPTIONS requests (pre flight). My app has no issues under 127.0.0.1 using this library, but as soon as I switched to localhost, I was hitting this same issue. Would really like to understand why. |
You can use this way. because it's work for me
it solve the cors issue |
Did someone find another solution? |
For me the problem was in defining endpoints before setting |
This before request setup worked for me
|
Thanks @mahendra-taiyo, This also worked for me. |
Sorry for adding a comment to this long open issue but hopefully this helps other people that end up here looking for a solution to their CORS issue. I tried all of the above and nothing helped. I finally noticed an error in the browser's console that said:
After some reading I realized I need to add this to my code: CORS(
app,
supports_credentials=True, # Add This
origins=["http://localhost:3000"], # You'll need this, you cannot use * (wildcard domain) when using supports_credentials=True
) Hopefully this helps out other people. |
Hey guys, I've been trying to get flask_cors to work for over two weeks now, so thought that I would write an issue.
Here's what is in the init.py file
The error that I'm getting is:
Went into the library to poke around and it looks like the after request isn't being called. The backend is running on localhost:5000 and the frontend is running on localhost:8080, any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: