0

I want to use an API running at localhost:8000/data into my angular app which is running at localhost:4200.

I am getting the below error in the browser.

Browser console

vivek
  • 21
  • 1
  • 3
  • please share your code as well. – Farhat Zaman Jul 28 '20 at 06:06
  • You can temporary disable CORS for dev purposes: https://stackoverflow.com/a/3177718/7415288 – Marat Mkhitaryan Jul 28 '20 at 06:37
  • I do not have time to write a full answer, but this option should do the trick (and will not require you to disable CORS locally): https://angular.io/guide/build#proxying-to-a-backend-server - Basically you will allow your frontend to issue the calls to `localhost:4200/api`, but have angular rewrite the outgoing call to `localhost:XXX/api` and disable CORS on the way automatically for development purposes. – Philipp Meissner Jul 28 '20 at 06:50
  • Setup: https://pypi.org/project/django-cors-headers/0.01/ And It's done. – Marin Jul 28 '20 at 07:48

1 Answers1

1

Its a backend "problem". The backend can use in local env:

Access-Control-Allow-Origin: *

Or you start the chrome without CORS, e.g. on mac

open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security