Proxy代理的设置

282 阅读1分钟
 proxy: {
        '/apis': {    //将www.exaple.com印射为/apis
            target: 'https://www.exaple.com',  // 接口域名
            secure: false,  // 如果是https接口,需要配置这个参数
            changeOrigin: true,  //是否跨域
            pathRewrite: {
                '^/apis': ''   //需要rewrite的,
            }              
        }
  }
  • /apis 当请求路径开头匹配到 /apis 则走代理
  • target -> 代理的地址
  • secure: https 需要开启
  • changeOrigin 跨域时需要开启
  • pathRewrite /api/xx最后代理的路径是http://xxx.xx.com/api/xx,netWork里看到的是http://localhost:3000/api/xx,科室我们不需要 /api 所以用pathRewrite重写用'^api/':'',把'/api'去掉,这样既能正确标识,又能在请求接口时去掉'api'