ant-design-vue-pro
ant-design-vue-pro copied to clipboard
后台接口部署上去,连接API 。前端报错,Proxy error: Could not proxy request
具误为体错Proxy error: Could not proxy request /code from localhost:8000 to http://xx.xx.xxx.xxx:8003 (ECONNREFUSED).
修改了vue.config.js 里面得devserver proxy 代理地址里
https://github.com/sendya/ant-design-pro-vue/issues/91
这个可能是bypass的方法没有添加最后的返回导致的
vue.config.js
module.exports = {
devServer: {
proxy: {
"/api": {
target: "http://localhost:3000",
bypass: function(req, res) {
console.log(req.path);
console.log(process.env.MOCK);
if (req.headers.accept.indexOf("html") !== -1) {
console.log("Skipping proxy for browser request.");
return "/index.html";
} else if (process.env.MOCK !== "none") {
const name = req.path
.split("/api/")[1]
.split("/")
.join("_");
console.log(name);
const mock = require(`./mock/${name}`);
const result = mock(req.method);
delete require.cache[require.resolve(`./mock/${name}`)];
return res.send(result);
}
return null;
}
}
}
}
Sometimes you don't want to proxy everything. It is possible to bypass the proxy based on the return value of a function.
In the function you get access to the request, response, and proxy options.
Return null or undefined to continue processing the request with proxy.
Return false to produce a 404 error for the request.
Return a path to serve from, instead of continuing to proxy the request.
修改了vue.config.js 里面得devserver proxy 代理地址里 ECONNREFUSED (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.(https://nodejs.org/api/errors.html#errors_common_system_errors) 代理地址要保持和项目在线调试地址一致,否则自己就得保证代理地址真实存在 @above-lilili