Antd Pro 服务挂掉 Disconnected from the devServer, trying to reconnect

文章目录

    今天发现 Antd Pro 的开发服务经常挂掉,浏览器中显示:

    Disconnected from the devServer, trying to reconnect…

    看起来是由于没有处理后台 404 的错误,导致前端 node 服务挂掉。。。

    [HPM] Error occurred while trying to proxy request /api/upload-image from localhost:8000 to http://localhost:8088 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
    events.js:292
          throw er; // Unhandled 'error' event
    

    然而我并没有找到可以包住异常的地方。

    原来并不是 404 导致的问题,而是 proxy 的配置问题。

    将 config/proxy.ts 中的 target 地址中的 localhost 替换成
    127.0.0.1 即可。

    再次启动服务,测试,就没有这个问题了。

    不知道是不是因为这两天折腾 WSL 1 版本切换 2 导致的。

    又挂了

    [HPM] Error occurred while trying to proxy request /api/upload-image from localhost:8000 to http://127.0.0.1:8088

    仔细看,本地 8000 也是 localhost。

    cat /etc/hosts
    # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
    # [network]
    # generateHosts = false
    127.0.0.1       localhost
    127.0.1.1       DESKTOP-FST75GU.localdomain     DESKTOP-FST75GU
    

    windows 里的也改了,还是不行。

    浏览器里这样访问:

    http://127.0.0.1:8000/

    参考

    https://github.com/saikat/react-apollo-starter-kit/issues/20

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式