devServer proxy shows the pass happening in the console, but doesn't work in browser
- Operating System: Mac OS 10.14
- Node Version: 10.2.1
- NPM Version: 5.6.0
- webpack Version: 4.17.1
- webpack-dev-server Version: 3.1.14
- [x] This is a bug
- [ ] This is a modification request
Code
// webpack.config.js
devServer: {
contentBase: dest,
inline: true,
proxy: {
"/api/v1/**": {
target: "http://localhost:3000/api/v1",
logLevel: "debug"
}
}
},
// additional code, remove if not needed.
axios
.get("/api/v1/test")
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});
Expected Behavior
When the axios request is made from the browser I expect the API request to be passed to the node/express server running on port 3000 via the webpack devserver proxy and then returned to the browser.
Actual Behavior
The request gets proxied, I can see it in the dev server output in the console:

But in the browser I get a 404 error:

And I can confirm the API route returns successfully on it's own:

I've tried altering my proxy settings per responses to similar github issue threads, but I can't seem to get it to work. The biggest difference I've seen in my issue and others online is that I can see the proxy pass happening in the console.
UPDATE
After typing this out and re-reading it, I notice that the path sections after the /api/v1 are not being passed in the proxy pass, e.g.
GET /api/v1/test -> http://localhost:3000/api/v1/ <-- test is not being passed through
The thing is, I have a json object that is passed back from requests going to api/v1 as well, and that is not being passed back either.
For Bugs; How can we reproduce the behavior?
Set up a project via the vue-cli, add the proxy config noted above, create a node-express server with the path:
app.get("/api/v1/test", (request, response) => {
response.json({ test: "worked" });
});
Maybe port missmatch 8080 and 3000?
How so? If I'm understanding correctly, the webpack dev server should be hosting from port 8080 for my front end code base and any requests to :8080/api/v1/... are passed to :3000/api/v1/... via the proxy. That should be what's happening, right?
Both the webpack dev server's code base and the express server are working from their respective port, it's just the proxy from one to the other and back that doesn't seem to be working.
@chris-schmitz can you create full minimum reproducible test repo and describe in readme what you actually have and what you expected?
Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!
I have the same issue. Did you solve the problem?