How is a proxy server supporting the server on a specific path?

Here are the route configurations:

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

Here is the proxy configuration for webpack-dev server:

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

The express server listens for 3000 ports.

I hope that all requests sent to http: // localhost: 3000 / service will be transferred to http: // localhost: 8080 , but it seems that response-router is processing all the requests, and the proxy server is down.

Does any body know how to fix this? Thank you in advance

+11
source share
2 answers
  1. Check out the Dev Server Webpack documentation, you need to provide an object with a target property.

  2. The documentation for http-proxy-middleware shows the use of patterns for matching.

In conclusion, I would try this:

 proxy: { '/service/**': { target: 'http://localhost:8080' } } 
+1
source

Make sure you handle promises for API calls correctly. I ran into the same problem when the client server was handling all API calls, and did not return a 404 error and proxy capture.

 fetch("/api/list") .then(res => res.json()) .then(data => { // handle the data }) 
0
source

All Articles