problem description
the newcomer has just come into contact with a question about the cross-domain resolution of webpack-server-dev.
has already configured the domain name of the proxy, but axios
directly requests the domain name + route after the proxy, and naturally returns 404, because there is no mockServer interface requested at all. Maybe I have some misunderstanding about this. I hope there is a great god to explain
the environmental background of the problems and what methods you have tried
for example, the server my mock server listens to is the 8009
port, while I direct the domain name of the interface to the project port 8008
. 404 is displayed when requesting with axios
, because this interface does not exist at all. Do you want to use fetch
?
related codes
mock Server Services: localhost: 8009
//webpack.config.js
module.exports = {
...
devServer: {
proxy: {
"/api": "http://localhost:8008",
}
},
...
}
//
axios.get("v1/api/tablelist")
.then(response => {
console.log("response =========>", response)
})
what result do you expect? What is the error message actually seen?
without adding a request header, you can not only solve cross-domain problems, but also successfully request data. Thank you
_
Update question: 2018.11.20
may have misunderstood proxy
before. First of all, my background interface address is http://localhost:8009/api/tablelist
, while the address of my project is http://localhost:8008
, so the address that needs to be proxied should be 8009
, right?
that is how to configure devServer.
...
devServer: {
proxy: {
"/api": "http://localhost:8009",
}
},
...
I don"t know if this understanding is correct. In addition, I set it like this, and the request interface was changed to
.axios.get("/api/tablelist")
.then(response => {
console.log("response =========>", response)
})
but why is the request url
in network still the 8008
port? Haven"t you already proxied to 8009
? Thank you
_ _
Update question: 2018.11.21
access to servers and interfaces can get interface data.
. networkurl http://localhost:8008/xxx