vue 项目如何配置多个 proxy 代理

163 阅读1分钟

vue.config.js

const web1 = 'http://192.168.xxx.xxx:8001'
const web2 = 'http://192.168.xxx.xxx:8002'
const web3 = 'http://192.168.xxx.xxx:8003'

然后在module.exports下的[devServer]中这样写:

proxy: {
      '/api/web': {
        target: web1,
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/api/web': ''
        }
      },
      '/api': {
        target: web2,
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      },
      ,
      '/': {
        target: web3,
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/': ''
        }
      }
    },