在项目src下新建setupProxy.js文件:
文件中写入:
const { createProxyMiddleware: proxy } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(proxy('/api', {
target: 'http://chst.vip',
pathRewrite: {
"^/api": ""
}
}));
};
控制台安装http-proxy-middleware
模块
安装命令:yarn add http-proxy-middleware
或者npm install http-proxy-middleware
重新启动项目:yarn start