2

Im trying to use angular proxy to proxy to my backend server. My server is running on http://localhost:8000 My angular server is running on http://localhost:4200

If the API makes a call to http://localhost:4200/api/bacon. I want it proxied to http://localhost:8000/api/bacon. However I only want calls that start with /api to be proxied.

My proxy.conf.json file looks like this.

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

And one of my api calls will look like this. http://localhost:4200/api/yemen

In this case I expect it to be proxied to http://localhost:8000/api/yemen

However it does not seem to be working

1 Answer 1

1

The full URL gets forwarded to the target because you didn't use pathRewrite, then you don't have to write /api in the target property.

Also if you want to have more informations next time, you can use logLevel: 'debug' to see incoming requests and their redirections.

{
  "/api": {
    "target": "http://localhost:8000",
    "secure": false,
    "logLevel": "debug"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.