Reputation: 107
I've never used a proxy before, so this is a very basic question. I've made my Angular app that is served on localhost:2000 and set all the routes, but afterwards realised I have to use a proxy (localhost:3000/api) like so:
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
I'm confused, because I don't have any routes configured in my app that would point to /api. I would like any request that is made to my application go trough this localhost:3000/api (not just the ones that has /api in URL, because they are non-existing), without changing too much of my routing module file.
Upvotes: 1
Views: 848
Reputation: 610
You can use "pathRewrite": {"^/api" : ""}
and change your configuration like below:
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"pathRewrite": {"^/api" : ""}
}
}
Request should be:
this.http.get<Parent>(api/<end-point>);
Upvotes: 1