"Connection refused" Angular 4 本地主机开发

"Connection refused" Angular 4 localhost development

我在本地获取 "Connection refused" 页面,而 运行 Angular 4 个应用程序。

URL 是 http://localhost:4200/

运行 带有 ng serve --open 命令的应用程序。

更新 1:angular.json

通过一些来源,我发现 angular cli 文件现在更改为 angular.json.

以下是来自 agnular.json

的详细信息
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
  "angular-forms": {
    "root": "",
    "sourceRoot": "src",
    "projectType": "application",
    "architect": {
      "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
          "outputPath": "dist",
          "index": "src/index.html",
          "main": "src/main.ts",
          "tsConfig": "src/tsconfig.app.json",
          "polyfills": "src/polyfills.ts",
          "assets": [
            "src/assets",
            "src/favicon.ico"
          ],
          "styles": [
            "src/styles.css"
          ],
          "scripts": []
        },
        "configurations": {
          "production": {
            "optimization": true,
            "outputHashing": "all",
            "sourceMap": false,
            "extractCss": true,
            "namedChunks": false,
            "aot": true,
            "extractLicenses": true,
            "vendorChunk": false,
            "buildOptimizer": true,
            "fileReplacements": [
              {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
              }
          ]
        }
      }
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "angular-forms:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "angular-forms:build:production"
        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "angular-forms:build"
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "karmaConfig": "./karma.conf.js",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.spec.json",
        "scripts": [],
        "styles": [
          "src/styles.css"
        ],
        "assets": [
          "src/assets",
          "src/favicon.ico"
        ]
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "src/tsconfig.app.json",
          "src/tsconfig.spec.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
},
"angular-forms-e2e": {
  "root": "",
  "sourceRoot": "",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "./protractor.conf.js",
        "devServerTarget": "angular-forms:serve"
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "e2e/tsconfig.e2e.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
}
},
"defaultProject": "angular-forms",
"schematics": {
"@schematics/angular:component": {
  "prefix": "app",
  "styleext": "css"
},
"@schematics/angular:directive": {
  "prefix": "app"
}
}
}

如果需要更多详细信息,请告诉我

附上屏幕截图以获取更多详细信息。

而不是 localhost 尝试使用您的 IP 访问您的应用,

(假设您正在使用 Windows)在您的命令行中,键入 => ipconfig 并复制 IP 地址 returns,

例如,如果 IP 地址是 192.168.0.10,那么您可以访问您的应用程序(在发布 ng server 之后),

http://192.168.0.10:4200

希望对您有所帮助!

我已经找到了解决方法,而且非常简单。当@Devid 向我询问有关公司代理的问题时,我已经开始朝这个方向寻找解决方案。最后我发现我的 LAN 代理设置有一个小错误。

配置代理服务器时,我忘记启用选项 "Bypass proxy server for local addresses",这导致出现上述错误。

下面是更多详细信息的屏幕截图。

转到命令行并 运行 ng serve --port 4200

希望对您有所帮助。

只需在 Chrome incognito/private 模式下打开相同的 URL 对我有用。这只是一种解决方法。