Falcon cors with Angular 2

434 Views Asked by At

I do not understand the setup below used to work but it suddenly broke.

I configured CORS on Falcon as follow (I run it via gunicorn):

cors = CORS(
  allow_all_origins=True,
  allow_all_headers=True,
  allow_all_methods=True
)

api = application = falcon.API(
  middleware=[
      cors.middleware,
      auth_middleware,
      sqlalchemy_middleware
  ]
)

On AngularJS

return this.authHttp.get(CONFIG.apiUrl + '/user').map(
        (res: Response) => res.json());

Using http.get with manually setting the token does not work. I have access to my token in localStorage.getItem('token').

I have got the following errors:

zone.js:2019 OPTIONS http://0.0.0.0:8000/user 401 (Unauthorized) XMLHttpRequest cannot load http://0.0.0.0:8000/user. Response for preflight has invalid HTTP status code 401

I searched everywhere on the internet and I understand it is a server issue... However the server used to work with that configuration.

Let me know if you have any idea.

Cheers,

1

There are 1 best solutions below

0
On

The solution was simple, I needed to disable the authentication from the FalconAuthMiddleware on 'OPTIONS' requests in my controller.

auth = {
    'exempt_methods': ['OPTIONS']
}