1

I am currently in the development phase of my application and am using a proxy-config.json file to map my API calls to the backend server running on a different port. At the moment, I have to specify each API call in my proxy-config file before using it. I have came across a problem when having to call an address with a parameter. I am not sure how I can implement this using the proxy-config file. I have something like this that is currently working correctly.

        "/migrations": {
         "target": "http://localhost:9090",
         "secure": false,
         "changeOrigin": true,
         "logLevel": "debug",
         "pathRewrite": {
         "^/migrations": "/service/api/migrations/"
         }

And I want to implement something like this:

        "/migrations/{id}": {
         "target": "http://localhost:9090",
         "secure": false,
         "changeOrigin": true,
         "logLevel": "debug",
         "pathRewrite": {
         "^/migrations/{id}": "/service/api/migrations/{id}/"
         }

Is something like this possible? Or do I have to resort to something else? Please help. Thank you :)

2 Answers 2

2

Actually,

I was actually able to fix my problem a different way. I was specifying every api call in my proxy-config.json file. This isn't the correct way to do it. Instead I needed to do something like this:

      "/service/api/*": {
      "target": "http://localhost:9090",
      "secure": false,
      "logLevel": "debug"
      }
      }

In this way, any url that begins with '/service/api/' will automatically redirect to desired host address. So now if I do a GET at '/service/api/migrations/id' it will point to 'localhost:9090/app/api/migrations/id'.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Try doing "/migrations/*" instead of "/migrations/{id}"

1 Comment

And in the pathRewrite don't include the {id} for the part that you're rewriting. Just rewrite "^/migrations/" : "/service/api/migrations/"

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.