vue3 多服务器域名跨域代理和请求配置

多服务器域名的跨域配置:
同样是在vue.config.js文件中对devServer.proxy进行配置,如下:

const {defineConfig} = require('@vue/cli-service')
module.exports = defineConfig({
    transpileDependencies: true,
    lintOnSave: false, //关闭eslint检查,
    devServer: {
        proxy: {
            //配置服务器地址一
            '/apis': {
                // target: 'http://xx.xx.xx.xx:8001', //lcoal 接口域名
                // target: 'http://xx.xx.xx.xx:7088', //dev 接口域名
                target: 'http://xx.xx.xx.xx:8088', //real 接口域名
                changeOrigin: true,             //是否跨域
                ws: true,                       //是否代理 websockets
                secure: true,                   //是否https接口
                pathRewrite: {                  //路径重置
                    '^/apis': ''
                }
            },
            //配置服务器地址二
            '/externalApis': {
                target: 'http://xx.xx.xx.xx:8000', //外部接口域名
                changeOrigin: true,             //是否跨域
                ws: true,                       //是否代理 websockets
                secure: true,                   //是否https接口
                pathRewrite: {                  //路径重置
                    '^/externalApis': ''
                }
            }
        }
    }

})

 

posted @ 2024-05-14 17:16  苹果芒  阅读(103)  评论(0编辑  收藏  举报