Make sure that your request url and port matches that which your webpack-dev-server is running on. So, if your api is located at http://localhost:5000
, and your dev server is running on http://localhost:8080
, make sure all of your requests are to http://localhost:8080
. Its best to make your requests to localhost:8080/api
(to avoid conflict with app routes) and use the path rewrite to remove the /api.
Example:
Webpack devserver proxy config:
proxy: {
'/api': {
target: 'http://localhost:5000',
pathRewrite: { '^/api': '' },
},
}
Webpack dev server running on:
http://localhost:8080
Desired API endpoint:
http://localhost:5000/items
In your app, make the request to:
http://localhost:8080/api/items
.
This should work. It seems to me that all of the above issues stem from making the request to the API url and port rather than the webpack dev server url and port and using the proxy and path rewrite to direct the request to the API.