Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to proxy to backend server on certain path?

Here is the routes config:

<Route path='/' component={CoreLayout}>
  <IndexRoute component={HomeView}/>
  <Route path='/404' component={NotFoundView}/>
  <Redirect from='*' to='/404'/>
</Route>

Here is the proxy config for webpack-dev-server:

proxy: {
  '/service': 'http://localhost:8080'
}

The express server listens on 3000 port.

I hope that all the requests send to http://localhost:3000/service would be transferred to http://localhost:8080, but it seems that react-router handles all the requests and the proxy does not work.

Any body knows how to fix this? Thank you in advance

like image 639
eyakcn Avatar asked Jan 19 '16 22:01

eyakcn


1 Answers

  1. Check Webpack Dev Server documentation, you need to provide object with target property.

  2. http-proxy-middleware documentation shows usage of patterns for matching.

In conclusion, I would try this:

proxy: {
  '/service/**': { target: 'http://localhost:8080' }
}
like image 50
Andrey Avatar answered Sep 26 '22 15:09

Andrey