1 react porxy 只代理一個
修改package.json文件
"proxy":"http://172.19.5.35:9536",
2 react配置多個代理,跨域
1):安裝http-proxy-middleware管理包为迈,
cnpm http-proxy-middleware --save
npm install http-proxy-middleware --save
$ yarn add http-proxy-middleware
2):在項目目錄src/下新建setupProxy.js文件捧韵,然后寫入如下代碼:
const proxy = require('http-proxy-middleware')
module.exports = function (app) {
app.use(proxy('/banner', {
target: 'https://ad.maoyan.com/',
secure: false,
changeOrigin: true,
pathRewrite: {
"^/banner": "/"
},
}))
app.use(proxy('/common', {
target: 'https://api.maoyan.com',
secure: false,
changeOrigin: true,
pathRewrite: {
"^/common": "/"
},
}))
app.use(proxy('/city', {
target: 'http://m.maoyan.com/',
secure: false,
changeOrigin: true,
pathRewrite: {
"^/city": "/"
},
}))
}