问题
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