如何使用 Angular-CLI 重写反向代理中的路径? [英] How can I rewrite the path in a reverse proxy with Angular-CLI?
问题描述
我已经使用 angular2 CLI 设置了反向代理,如下所示:
I have set up the reverse proxy with the angular2 CLI like the following:
{
"/api/customer/*": {
"target": "http://localhost:9010",
"secure": false
}
}
我的问题是远程 API 在路径/customer 上暴露了一个服务,但是反向代理发送的请求在/api/customer 上.
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.
有没有办法从反向代理发送的请求中删除/api?(不要回答只需从您的 http 请求中删除/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).
推荐答案
你可以很容易地做到这一点,使用 pathRewrite
选项,如下所示:
You can do this fairly easy, using the pathRewrite
option like so:
proxy: {
'/api/customer/*': {
target: 'http://localhost:9010',
pathRewrite: {'^/api' : ''}
}
}
您还可以查看更新的 Webpack 文档以了解更多信息信息.
You can also take a look at the Updated Webpack documentation for further information.
这篇关于如何使用 Angular-CLI 重写反向代理中的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!