Foker
Foker

Reputation: 1011

Rewriting path with http-proxy-middleware

Trying to rewrite path of request with http-proxy-middleware. But trouble is that when i am writing such code:

proxyMiddleware('/service/api', {target: 'http://192.168.70.99:8078/'});

It means that path like /service/api/export/1 will be redirected to http://192.168.70.99:8078/service/api/export/1; But I need to redirect it to http://192.168.70.99:8078/export/1. How can I do that?

Upvotes: 13

Views: 25555

Answers (1)

hassansin
hassansin

Reputation: 17508

You can pass the pathRewrite opiton and inside it use regex pattern to remove the path that you don't need:

proxyMiddleware('/service/api', {
  target: 'http://192.168.70.99:8078/',
  pathRewrite: {
    '^/service/api':'' //remove /service/api
  }
});

Upvotes: 26

Related Questions