Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 983
Nano Avatar asked Feb 01 '17 09:02

Nano


1 Answers

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 Updated Webpack documentation for further information.

like image 58
alex kucksdorf Avatar answered Sep 28 '22 05:09

alex kucksdorf