我已经使用angular2 CLI设置了反向代理,如下所示:
{
"/api/customer/*": {
"target": "http://localhost:9010",
"secure": false
}
}
我的问题是远程API在路径/客户上公开服务,但反向代理发送的请求在/ api / customer上。
有没有办法从反向代理发送的请求中删除/ api? (不要回答“只需从你的http请求中删除/ api”,因为我在/ customer上有一个有角度的路由)。
谢谢,
纳米
使用pathRewrite
选项可以很容易地做到这一点,如下所示:
proxy: {
'/api/customer/*': {
target: 'http://localhost:9010',
pathRewrite: {'^/api' : ''}
}
}
您还可以查看Webpack documentation以获取更多信息。