Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 750
Foker Avatar asked Jul 13 '15 21:07

Foker


1 Answers

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
  }
});
like image 121
hassansin Avatar answered Sep 20 '22 18:09

hassansin