https://github.com/youzan/zan-proxy/blob/master/README.zh-CN.md

    适用于 dva, umijs
    修改前端启动命令 SOCKET_SERVER=none,关闭 socket server

    1. "start": "cross-env APP_TYPE=site PORT=8899 SOCKET_SERVER=none umi dev",
    2. "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 这一段

    1. // Connect to WebpackDevServer via a socket.
    2. if (process.env.SOCKET_SERVER !== 'none') {
    3. socket(
    4. process.env.SOCKET_SERVER
    5. ? `${stripLastSlash(process.env.SOCKET_SERVER)}/sockjs-node`
    6. : url.format({
    7. protocol: window.location.protocol,
    8. hostname: window.location.hostname,
    9. port: window.location.port,
    10. // Hardcoded in WebpackDevServer
    11. pathname: '/sockjs-node',
    12. }),
    13. {
    14. onclose() {
    15. if (
    16. typeof console !== 'undefined' &&
    17. typeof console.info === 'function'
    18. ) {
    19. console.info(
    20. 'The development server has disconnected.\nRefresh the page if necessary.',
    21. );
    22. }
    23. },
    24. onmessage(e) {
    25. var message = JSON.parse(e.data);
    26. switch (message.type) {
    27. case 'hash':
    28. handleAvailableHash(message.data);
    29. break;
    30. case 'still-ok':
    31. case 'ok':
    32. handleSuccess();
    33. break;
    34. case 'content-changed':
    35. // Triggered when a file from `contentBase` changed.
    36. window.location.reload();
    37. break;
    38. case 'warnings':
    39. handleWarnings(message.data);
    40. break;
    41. case 'errors':
    42. handleErrors(message.data);
    43. break;
    44. default:
    45. // Do nothing.
    46. }
    47. },
    48. },
    49. );
    50. }