proxy: {
"/api": {
// 测试环境
target: "http://192.168.0.79:8080", // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
"^/api": "",
},
onProxyReq: function (proxyReq, req, res, options) {
if (req.body) {
let bodyData = JSON.stringify(req.body);
// incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
proxyReq.setHeader("Content-Type", "application/json");
proxyReq.setHeader("Content-Length", Buffer.byteLength(bodyData));
// stream the content
proxyReq.write(bodyData);
}
},
},
},
具体可以查看:https://github.com/chimurai/http-proxy-middleware/issues/40