0

I implemented CORS on my Django backend by installing django-cors-headers and following the steps mentioned in- https://github.com/OttoYiu/django-cors-headers. Essentially, I performed the following steps-

  1. pip install django-cors-headers
  2. INSTALLED_APPS = ( ... 'corsheaders', ... )
  3. MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', ... ]

  4. CORS_ORIGIN_WHITELIST = ( 'localhost:8000', #LB '10.254.138.226:443' )

I still can not make it work when I use my angular front-end. For example, my POST request becomes OPTIONS.

zone.js:2935 OPTIONS https://10.254.138.226/api/users 0 () error is ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …}

I don't have this problem when I use postman. Could someone help?

To provide more context- I have the front end and the back end (DRF) running on two different machines. In fact, I have 2 instances of the back end running in two different machines and I have a load balancer mapping the requests from <LB IP>:443 to one of the <Backend IP>:8000 base-url.

1 Answer 1

0

I will possibly never find out the exact issue as to why it was happening. I just deleted and recreated the LB and everything started working automagically.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.