Nolyurn
Nolyurn

Reputation: 608

Webpack proxy, how to redirect when url end with specific path?

I'd like that when i try to access this URL :

http://localhost:8080/123456/activites-digitales

Proxy redirect request to this address :

http://localhost:8082/activites-digitales

I have an api on port 8082 which return JSON.

With my current config file it work for :

http://localhost:8080/activites-digitales

But not :

http://localhost:8080/123456/activites-digitales

123456 could be any number, it's a route parameter, what should i change in my configuration ?

I've got the following devServer conf :

devServer: {
    hotOnly: true,
    index: 'index.html',
    port: 8080,
    proxy: {
      '/activites-digitales': 'http://localhost:8082/'
    }
}

I ever tried '*/activites-digitales', '/**/activites-digitales'

webpack and webpack-dev-server 2.3

Upvotes: 1

Views: 4955

Answers (2)

Duc Anh Tao
Duc Anh Tao

Reputation: 84

You can use the pathRewrite config like the below:

proxy: {
            "/123456/activites-digitales": {
                target: "http://localhost:8082/",
                pathRewrite: {"^/123456": ""}
            }
        }

More info here

Upvotes: 3

rakesh shrestha
rakesh shrestha

Reputation: 1455

You are redirecting your host port 8080 to port 8082 in your code.

http://localhost:8082/

Upvotes: 0

Related Questions