1、安装http-proxy-middleware
npm install http-proxy-middleware -D
2、在src下面新建setupProxy.js文件
const { createProxyMiddleware } = require('http-proxy-middleware')
// koa
module.exports = function (app) {
// 没有太严谨,bike1 api2也可以
app.use(/^\/bike|\/api/, createProxyMiddleware({
target: 'http://1.116.64.64:5004/',
logLevel: 'debug',
changeOrigin: true,
"pathRewrite": {// 如果接口本身没有/api需要通过pathRewrite来重写了地址,这里把/api转成‘’
"^/api": ""
}
}))
// .use('/bike',
// createProxyMiddleware({
// target: 'http://1.116.64.64:5004/',
// logLevel: 'debug',
// changeOrigin: true
// }))
}