Angular and Node are running Amazon EC-2 instances. Angular in port 4200 and Node in 3000. When I try to do anything with Angular to connect with Node, Its throwing CORS error. Anyone why and how to sort out?
Asked
Active
Viewed 608 times
0
-
Have you enabled CORS from your nodejs application? – Pardeep Jain Jan 17 '19 at 05:45
-
yes I have enabled. Its working fine when we use it in local but when we deploy its throwing CORS error – Sidhu Tesingu Jan 17 '19 at 05:46
-
Q: Did you get the problem resolved? Otherwise, Q: Are you using a proxy, and if so, what is the configuration? Q: Any additional details about "what's different" between running locally and running under AWS? ALSO: If you're using `ng serve` on AWS, you know that's a "bad idea" for production use, correct? – paulsm4 Jan 18 '19 at 06:21
1 Answers
4
Your BEST bet is to run
ng build
(or equivalent) and serve your Angular app directly from your NodeJS web server.Your alternative is to configure your Angular app (it sounds like you're running the WebPack server used by the Angilar CLI, i.e.
ng serve
) to use a proxy:ng serve --proxy-config proxy.conf.json
.Here are several links about how to do that:
Another alternative (which can be used in conjunction with the above) is to configure CORS:
CORS in Express using TypeScript
Should you do this, you also need to add the CORS "Allow Origin" header in your Angular app:
`'Access-Control-Allow-Origin':'*',`

paulsm4
- 114,292
- 17
- 138
- 190