使用 proxy报错
Error occurred while trying to proxy request
node 版本 10+
代码
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
proxy('/api', {
target: 'http://xxx.xxx.xx.xxx:8080',
pathRewrite: { '^/api': '' },
secure:false
})
);
};
排查了好久
解决办法
添加请求头设置Connection:keep-alive
module.exports = function(app) {
app.use(proxy('/api', {
target: 'http://127.0.0.1:8080/',
pathRewrite: { '^/api': '' },
secure:false
headers: {
"Connection": "keep-alive"
},
}));
};
参考:http-proxy-middleware github