Angular HttpClient fails to proxy

Viewed 5996

I have a spring boot back-end api and I am trying to call a service for uploading or getting images from angular project. I have a standard proxy.conf.json file:

{
   "/api": {
      "target": "localhost:8080",
      "secure": false,
      "logLevel": "debug"
   }
}

if my angular service is using Http(HttpModule) everything is ok, but since its deprecated and i want to do it the new way i am trying with HttpClient(HttpClientModule) but in log i am getting :

[HPM] Error occurred while trying to proxy request /upload/ from localhost:4200 to localhost:8080 (ENOTFOUND) (https://nodejs.org/api/errors.html#errors_common_system_errors)

and it is not working. On one try on a linux machine i got the same mistake but with (EINVAL). Can someone guide me what i am doing wrong ? Sorry if the question is stupid there are a few questions like this one but neither of their solutions does not seem to work in my case.

1 Answers

Try to set http protocol in front of the localhost link.

{
   "/api": {
      "target": "http://localhost:8080",
      "secure": false,
      "logLevel": "debug"
   }
}
Related