Vue 项⽬ devServer.proxy 代理配置

环境

  • node v14.19.0
  • npm 6.14.16
  • @vue/cli 5.0.4

配置

module.exports = {
    devServer: {
        open: true,                                   // 自动用浏览器打开网页,默认是true
        openPage: '/login',                           // 打开指定 URL 的网页
        host: "localhost",                            // 代理主机
        port:8080,                                    // 代理端口
        disableHostCheck: true,                       // 禁用默认检查hostname
        proxy: {
            "/api": {                                 // 需要代理的路径
                target: "http://localhost:80",        // 代理到目标服务器地址,这⾥设置的地址会代替axios中设置的baseURL
                changeOrigin: true,                   // 如果接⼝跨域,需要进⾏这个参数配置
                secure: false,                        // 设置支持https协议的代理
                // ws:true,                           // proxy websockets
                pathRewrite: {
                    "^/api": "/"                      // 替换URL中的字符串  
                    // pathRewrite:{"^/api":"/"} 重写之后url为 http://localhost:80/xxxx    
                    // pathRewrite:{"^/api":"/api"} 重写之后url为 http://localhost:80/api/xxxx
                }
            }
        }
    },
}

你可能感兴趣的:(Vue 项⽬ devServer.proxy 代理配置)