Link to home
Start Free TrialLog in
Avatar of Federico Nardone Aggiutorio
Federico Nardone Aggiutorio

asked on

Angular, proxy works in local but not in remote

Dear users,
in my Angular 10 appI have a proxy file; all API call are forwarded to other link. In local it works perfectly; in remote not.

1) The call is a fake REST call I found in the web; so, the problem is for sure not this.
2) In remote, I push the app under a GIT and the build is created by a CI/CD process implemented from other developers.
3) I already added "proxyConfig": "proxy.conf.json" in my angular.json under serve; if there were the error, it wouldn't work also in local. So, the error is not in this point, I think.

I have the sensation, the proxy doesn't work only in remote. How can I solve the problem? Where could I find the error? Thank so much!

Avatar of David Favor
David Favor
Flag of United States of America image

If your API endpoint code is running on a local address, then this local address is private/unroutable, so will never be able to respond to any public IP requests.

This is the same for your proxy, so when using a proxy (whatever that might mean), your proxy must be listening on a public IP.

If I understand your question above, likely this is the problem.
Avatar of Federico Nardone Aggiutorio
Federico Nardone Aggiutorio

ASKER

Thank you very much for your reply; I try to explain by semplifyng as much as possible by an example.

In my Angular app I call a fake REST endpoint, we can assume, a free fake eindpoint available on the web. I have a proxy.conf.json with the row  "target": "www.testapi.com/addressbook".

On local, by ng serve, all works correctly and I receive in my terminal an output with a list of address. If I upload on remote server, it doesn't work and I see the html code of the home page (tipical behaviour of a missing data retrieving).

Why it's happens? How can I reach this fake end point also from the server?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.