https://github.com/youzan/zan-proxy/blob/master/README.zh-CN.md
适用于 dva, umijs
修改前端启动命令 SOCKET_SERVER=none,关闭 socket server
"start": "cross-env APP_TYPE=site PORT=8899 SOCKET_SERVER=none umi dev","start:no-mock": "cross-env MOCK=none PORT=8899 SOCKET_SERVER=none umi dev",
- 解决报错:npm run start 之后页面一直提示 Disconnect 不断刷新重连
- 原因:同时起了 devServer 和 node 两个端口服务,当访问后端渲染页面时,umi 中的 socket server 端口指向错误。所以它会不断地重连
当 SOCKET_SERVER=none 时就不会走 socket server 这一段
// Connect to WebpackDevServer via a socket.if (process.env.SOCKET_SERVER !== 'none') {socket(process.env.SOCKET_SERVER? `${stripLastSlash(process.env.SOCKET_SERVER)}/sockjs-node`: url.format({protocol: window.location.protocol,hostname: window.location.hostname,port: window.location.port,// Hardcoded in WebpackDevServerpathname: '/sockjs-node',}),{onclose() {if (typeof console !== 'undefined' &&typeof console.info === 'function') {console.info('The development server has disconnected.\nRefresh the page if necessary.',);}},onmessage(e) {var message = JSON.parse(e.data);switch (message.type) {case 'hash':handleAvailableHash(message.data);break;case 'still-ok':case 'ok':handleSuccess();break;case 'content-changed':// Triggered when a file from `contentBase` changed.window.location.reload();break;case 'warnings':handleWarnings(message.data);break;case 'errors':handleErrors(message.data);break;default:// Do nothing.}},},);}
