问答

如何配置vue.config.js的proxy?

作者:admin 2021-05-14 我要评论

一些接口要代理到地址1 一些接口要代理到地址2 我配置了vue.config.js: devServer: { proxy: { "/": { target: "https://www.ylcx.online:442", secure: true },...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

一些接口要代理到地址1
一些接口要代理到地址2

我配置了vue.config.js:

devServer: {
    proxy: {
      "/": {
        target: "https://www.ylcx.online:442",
        secure: true
      },
      "/proxy2": {
        target: "https://www.ylcx.online:441",
        secure: true
      },
    }
  }

请求的地址我写的是:
url: "proxy2/company/getCompanyList",

期望请求的实际地址是:
https://new.ylcx.online:441/company/getCompanyList

为什么这样对应不上接口?

###
"/proxy2": {
        target: "https://www.ylcx.online:441",
        secure: true,
        changeOrigin: true,
        pathRewrite: {'^/proxy2' : ''}
      },
###

"/proxy2": {

target: "https://www.ylcx.online:441",
ws: true,
changeOrigin: true,
pathRewrite: {
    "^/proxy2": "/"
}

},

试试这样呢 然后把上面那个 / 的代理给去掉 你设置的名字最好不要和地址栏里面有重复

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 请问下prometheus怎么进行自定义的按业

    请问下prometheus怎么进行自定义的按业

  • 节流函数为什么,点击无效,监听窗口大

    节流函数为什么,点击无效,监听窗口大

  • express访问静态资源失败

    express访问静态资源失败

  • IE 浏览器下 match 方法报错

    IE 浏览器下 match 方法报错

腾讯云代理商
海外云服务器