Getting CORS error in angularJS front end Getting CORS error in angularJS front end flask flask

Getting CORS error in angularJS front end


Eyooo, it is actually on your server side. You need to provide correct headers.

So you've tried this, I have no experience with flask but this I don't like;

response.headers.add('Access-Control-Allow-Origin','http://localhost:8100')

for testing purposes I suggest you just change the http:// part, to *so

 response.headers.add('Access-Control-Allow-Origin','*')

If that doesn't work verify that the header is actually being set, you could use a different program which doesn't care for CORS like postman or directly calling it in the browser if it doesn't depend on Accept headers.

here is some more readings about what it all is about.https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

EDIT:

Ok silly of me: The response had HTTP status code 503.This part in the error actually states what kind of response your server is giving, so currently there is an error on your server side. This happens when it is f/e down or what not.

So it seems that you're not doing anything strange, but your server side seems broken.

XMLHttpRequest cannot load http://ec2-..../api/loginStatus/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 503.

So this error here, I suggest looking at your headers, and maybe disable some. You currently allow only 2 request headers that might cause some issues as well?


Flask-CORS

A Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible.

Installation

Install the extension with using pip, or easy_install.

 $ pip install -U flask-cors

Simple Usage

In the simplest case, initialize the Flask-Cors extension with default arguments in order to allow CORS for all domains on all routes. Read More.

from flask import Flaskfrom flask_cors import CORS, cross_originapp = Flask(__name__)CORS(app)@app.route("/")def helloWorld():  return "Hello, cross-origin-world!"

Reference: https://flask-cors.readthedocs.io/en/latest/