首页 > 解决方案 > 为什么我只在 MAC OSX 中的代理调用上不断收到 ECONNRESET 错误,对于一些成功的调用完全是任意的(非常绝望)

问题描述

开发团队正在运行相同的代码,他们使用 UNIX 机器,我使用 MAC。我们有一个 Maven 项目 API 与前端 Angular 分离。Angular 在开发模式下对 API 进行代理调用。

我收到 ECONNRESET 错误,无法保存或加载某些结果。相当随意,因为它们中的大多数都可以解决。

到目前为止,我尝试了人们在代理设置上建议的所有技巧,方法是使用 * 或使用 IP 而不是 localhost 名称等。其中三个必须与 MAC OS 相关。这是proxy.config中的代理设置代码

{
  "/emport-api/*": {
    "target": "http://localhost:8080",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

这是 package.json 中的部分

    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --proxy-config proxy.conf.json --extract-css=true",
    "build": "ng build --prod --progress export.modal.component.ts --output-path dist",
    "test": "jest",
    "codecoverage": "jest --coverage",
    "test:watch": "jest --watch",
    "lint": "ng lint",
    "fixlinting": "ng lint --fix",
    "e2e": "ng e2e"
  },

这是错误之一

[HPM] GET /emport-api/rest/user/accessControl -> http://localhost:8080
[HPM] Error occurred while trying to proxy request /emport-api/rest/user/accessControl from localhost:4200 to http://localhost:8080 (ECONNRESET) 

如果我需要在此处放置某些信息以便更好地解释问题,请让我现在。

标签: node.jsangular

解决方案


在尝试了所有其他方法(包括给出超时持续时间)后找到了解决此问题的方法,只有保持连接活动选项为我解决了这个问题。

添加

"headers": {
  "Connection": "keep-alive"
 }

到 api 对象


推荐阅读