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

4
  • please share your code as well. Commented Jul 28, 2020 at 6:06
  • You can temporary disable CORS for dev purposes: stackoverflow.com/a/3177718/7415288 Commented Jul 28, 2020 at 6: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): 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. Commented Jul 28, 2020 at 6:50
  • Setup: pypi.org/project/django-cors-headers/0.01 And It's done. Commented Jul 28, 2020 at 7:48

1 Answer 1

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
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.