create-react-app和vue-cli配置跨域代理

2019-09-29  本文已影响0人  Issho

☼ 注:笔者的文章是根据自己当前项目做的笔记,具体应用请参照自己实际项目情况

1、安装http-proxy-middleware
npm install http-proxy-middleware --save
2、react:在src文件夹下新建一个setProxy.js文件
const proxy = require("http-proxy-middleware");

module.exports = function(app) {
    app.use(
        proxy(['/c', '/v1'], {
            target: 'https://10.8.20.25',
            changeOrigin: true,
            secure: false // https协议需要设置
        })
    )
}
3、Vue:在根目录新建一个vue.config.js文件
module.exports = {
    devServer: {
        proxy: {
            '/c': {
                target: 'https://10.8.20.25',
                changeOrigin: true,
                secure: false
            },
            '/v1': {
                target: 'https://10.8.20.25',
                changeOrigin: true,
                secure: false
            }
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读