1

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.

1
  • 1
    Can you please update your question to include an example of an HttpClient call you are making, specifically what URL you are passing that HttpClient call? Also what path are the endpoints on your server that you call from angular registered under? The configuration that is in the proxying to a backend server is specifically expecting the urls like /api/something to be passed to HttpClient with the server have paths such as /api/foo registered. Commented Nov 20, 2019 at 17:40

1 Answer 1

1

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>);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, it seems exactly what I'm looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.