this is my vue cross-domain configuration
proxyTable: {
"/api":{
target:"https://api.douban.com",
changeOrigin:true,
pathRewrite:{
"^/api":""
},
"/node":{
target:"http://127.0.0.1:3000",
changeOrigin:true,
pathRewrite:{
"^/node":""
}
}
}
in the above configuration, the first cross-domain request Douban music works well, and the second cross-domain local node server is not. This server is an api of NetEase cloud music written by a great god on the Internet
my axios request
getMusician: function({commit}){
axios.get("/node/personalized/newson")
.then(function(response){
console.log(response);
commit("addMusician", response.result.slice(0,4));
})
.catch(function(err){
console.log(err)
})
}
Cross-domain configuration of node server
app.all("*", function(req, res, next) {
if (req.path !== "/" && !req.path.includes(".")) {
res.header("Access-Control-Allow-Credentials", true)
// origin *
res.header("Access-Control-Allow-Origin", req.headers["origin"] || "*")
res.header("Access-Control-Allow-Headers", "X-Requested-With")
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
res.header("Content-Type", "application/json;charset=utf-8")
}
next()
})
when I make a cross-domain request, the browser reports an error
which god can help