预先 安装 http-proxy-middleware
npm i http-proxy-middleware
然后 src 目录下新建文件 setupProxy.js
const {createProxyMiddleware: proxy} = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
proxy('/api', {
target: 'http://xxxx/',
//secure: false,//是否验证htpps的安全证书,如果域名是https需要配置此项
changeOrigin: true,//必须设置为true
pathRewrite: {
"^/api": "/",
},
})
);
}