0

I am building an angular2 app with node as server,below is my api..

http://localhost:3000/api/auth/getcategories

When i called the abpove api,i got the following error in my console,

XMLHttpRequest cannot load http://localhost:3000/api/auth/getcategories. 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:8000' is therefore not allowed access.

I am not sure about the next step to solve the above issue,can anyone suggest help......

MMR
  • 2,869
  • 13
  • 56
  • 110

1 Answers1

0

Server must return set of CORS headers. In this particular case you should add to response following header:

Access-Control-Allow-Origin: *

Of course on production environment allowing all origin hosts (*) probably is not a good idea.

If you cannot add header to server's response, you can disable checking CORS headers by running Chrome with --disable-web-security and --user-data-dir flags.

Community
  • 1
  • 1
qzb
  • 8,163
  • 3
  • 21
  • 27