https://github.com/angular/angular-cli#proxy-to-backend here is an instruction how to do proxying to backend. I did everything step by step and still requests aren't proxied.
8080 - my Express backend 4200 - my Angular2 frontend
In Angular2 project I have file proxy.conf.json
with content like this:
{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}
In Angular2 package.json I changed start
procedure to "start": "ng serve --proxy-config proxy.conf.json"
When I type inside commander npm start
then at the start I can see Proxy created: /api -> http://localhost:8080
. Well, so far is good I guess.
I'm trying to send a request (Angular2)
constructor(private http: Http) {
this.getAnswer();
}
getAnswer(): any {
return this.http.get("/api/hello")
.subscribe(response => {
console.log(response);
})
}
I'm getting an error that http://localhost:4200/api/hello 404 (Not Found)
. As we can see, nothing has been proxied. Why? Did I do something wrong?
To be clear. When I go manually to http://localhost:8080/hello
, all works fine. There is nothing to look for in backend side.