如何使用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 Webpack documentation for further information.
这篇关于如何使用Angular-CLI在反向代理中重写路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!