修改vue代理后报错

 后面注释的是之前的地址,我改成了本地。

最前面的注释是别人写的,我也没太读懂

  // 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
    devServer: {
        disableHostCheck: true,
        proxy:{
            "/":{
                ws:true,
                target:"http://localhost:8080/",
                // target:"http://118.190.208.146:8080/"
            }
        },
    },

 

刚刚运行不会报错,页面加载出来,就会报错

刚刚运行不会报错,页面加载出来,就会报错



  App running at:
  - Local:   http://localhost:6317/
  - Network: http://192.168.3.66:6317/

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! globescene-portal@0.1.0 serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the globescene-portal@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\MR\AppData\Roaming\npm-cache\_logs\2021-05-06T09_51_24_956Z-debug.log

出现这个原因,是因为转发的后端socket服务重启,而客户端还在不停发起socket服务的重连,导致报错,最终导致webpack-dev-server服务挂了
解决方案:
webpack-dev-server启动时,监听进程报错,避免因为报错而中断了服务

process.on('uncaughtException', e => {
    console.log(e)
}})

你把pathRewrite加上试试 ,还有就是你的意思是把 /替换为http://45.105.124.130:8081因该不太行

  //vue-cli3.0 里面的 vue.config.js做配置
devServer: {
    proxy: {
        '/rng': {     //这里最好有一个 /
            target: 'http://45.105.124.130:8081',  // 后台接口域名
            ws: true,        //如果要代理 websockets,配置这个参数
            secure: false,  // 如果是https接口,需要配置这个参数
            changeOrigin: true,  //是否跨域
            pathRewrite:{
                '^/rng':''
            }
        }
    }
  }