0

My angular-cli version is 1.4.4, I follow the construction here to set backend proxy: How to set backend proxy with angular-cli

So I generate a file called proxy.conf.json next to package.json, the content is:

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

However, When I type command ng serve --proxy-config proxy.conf.json, I didn't see any tip to say proxy has been set, the output is : startup info As you can see, it only has info of webpack compiling, no info about [HPM] Proxy created: /api -> http://localhost:8080 has been outputed.

And now I have an api call, the api route is /api/authenticate. I suppose it should redirect to http://localhost:8080/api/authenticate, however it didn't, still point to http://localhost:4200/api/authenticate, of course it return 404 not found. Can anyone tell me why ?

ahwyX100
  • 585
  • 2
  • 9
  • 22

1 Answers1

0

I had the same issue, I solved the problem by adding "pathRewrite" key to the JSON.

So change your proxy config file to this.

{
 "/api": {
 "target": "http://localhost:8080",
 "secure": false,
 "pathRewrite": {"^/api" : "/api"}
 }
}

And yes, the webpack compiling did not show any info about my proxy configuration as well.

EDIT 1: If you are still not getting it, check this link Angular-CLI proxy to backend doesn't work

Also run your server using "serve" instead of "start". For instance

ng serve --proxy-config proxy.conf.json

Srinivas Valekar
  • 1,083
  • 10
  • 19