美文网首页
create-react-app和vue-cli配置跨域代理

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

作者: Issho | 来源:发表于2019-09-29 09:17 被阅读0次

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

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
            }
        }
    }
}

相关文章

网友评论

      本文标题:create-react-app和vue-cli配置跨域代理

      本文链接:https://www.haomeiwen.com/subject/ogljuctx.html