How can I rewrite the path in a reverse proxy with Angular-CLI?

人盡茶涼 提交于 2020-01-03 08:44:11

问题


I have set up the reverse proxy with the angular2 CLI like the following:

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

My problem is that the remote API is exposing a service on the path /customer, but the request that is sent by the reverse proxy is on /api/customer.

Is there a way to remove the /api from the request that is sent by the reverse proxy? (Don't answer with "just remove the /api from your http request", because I have an angular route on /customer).

Thank you,

Nano


回答1:


You can do this fairly easy, using the pathRewrite option like so:

proxy: {
    '/api/customer/*': {
        target: 'http://localhost:9010',
        pathRewrite: {'^/api' : ''}
    }
}

You can also take a look at the Webpack documentation for further information.



来源:https://stackoverflow.com/questions/41975937/how-can-i-rewrite-the-path-in-a-reverse-proxy-with-angular-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!