Angular Cors error

28 views
Skip to first unread message

Felipe Miranda

unread,
Jan 25, 2020, 12:38:12 AM1/25/20
to Angular and AngularJS discussion
Hi, i am consuming rest services from an external server, in develop i solve the Cors error with a proxy.conf.json file. How i solve this problem when i pass to production?

Sander Elias

unread,
Jan 25, 2020, 1:12:07 AM1/25/20
to Angular and AngularJS discussion
Hi Felipe,

Put a proxy in your production server. Most servers have configuration options for this.

Regards
Sander

manish pamnani

unread,
Feb 4, 2020, 12:42:13 AM2/4/20
to Angular and AngularJS discussion
CORS generally occurs due to one of the following reason:

- Hitting the Server from a localhost file(like localhost:4200/index.html)
- Hitting an External API which is not hosted on your server i.e. (api.fontawesome.com/login)
- Hitting an Internal API from your App.
- Hitting an API which is on https from an http origin.

To solve the CORS issue you can use the CORS header called Access-COntrol-Allow-Origin and set it to * to allow it from any origin like this:

Access-Control-Allow-Origin: *

This way it will allow it to access any URL from any Origin. 

Refer to below article for more info:

https://daveceddia.com/access-control-allow-origin-cors-errors-in-angular/
Reply all
Reply to author
Forward
0 new messages