栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Cocos2d-x

Vue 2.6 配置 多个proxy代理

Cocos2d-x 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Vue 2.6 配置 多个proxy代理

1. 官方文档 vue-cli中 配置参考proxy

写的配置多个代理如下代码,官方地址

module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: '',
        ws: true,
        changeOrigin: true,
        pathRewrite: { //我自己添加,路径重写
            '^api': ''
        }
      },
      '/foo': {
        target: ''
      }
    }
  }
}

确实还不够用,还要配置pathRewrite,有些还要好好解释一下

ws: true,  //代理websockets

changeOrigin: true, // 是否跨域,虚拟的站点需要更管origin
pathRewrite: 这部分是路径重写,因为上面前端请求接口多增加 api,需要匹配到时,删除api,这个用来匹配代理的字符串

关于具体pathRewrite 路径重写知识如下图,具体官网地址


2. 自己做的案例

背景:访问百度开放地图接口,所以前端必须要代理,不然就会产生跨域

//App.vue




//vue.config.js

module.exports = {
  devServer: {
    proxy :{
      '/api':{
        target: "https://api.map.baidu.com",
        ws: true,  //代理websockets
        changeOrigin: true,  是否跨域,虚拟的站点需要更管origin
        pathRewrite: {
          '^/api': ''
        }
      },
      '/test':{
        target: "https://api.map.baidu.com",
        ws: true,  
        changeOrigin: true,
        pathRewrite: {
          '^/test': ''
        }
      }
    }
  }
}

3. 解释多个代理匹配的问题 在浏览器中看到的结果:api其实还在,其实访问是正确的,因为这里就是这样,隐藏真实访问路径( 真实访问路径 /place/v2/search/.. )

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/951704.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号