“Connection refused” Angular 4 localhost developme

2019-08-20 04:40发布

I am getting "Connection refused" page while running Angular 4 app locally.

URL is http://localhost:4200/

Running the app with ng serve --open command.

UPDATE 1: angular.json

With some sources I have found that the angular cli file is now changed as angular.json.

bellow are the details from 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"
}
}
}

Please let me know if more details required

Screenshot is attached for more details.

enter image description here

3条回答
劳资没心,怎么记你
2楼-- · 2019-08-20 05:29

I have found a solution for this and it is quite simple. As @Devid ask mi about corporate proxy the I have started searching solution in this direction. Finally i have found that there was minor mistake in my LAN proxy settings.

While configuring proxy server I forget to enable the option "Bypass proxy server for local addresses" and which is causing mi above error.

Below is the screenshot for more details.

enter image description here

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-08-20 05:31

Go to command line and run ng serve --port 4200.

Hope this helps.

查看更多
混吃等死
4楼-- · 2019-08-20 05:44

Instead of localhost try accessing your app using your IP like this,

(Assuming that you're using Windows) In your command line, Type => ipconfig and copy the ip address it returns,

For, Eg if the IP address is, 192.168.0.10 then, you can access your application (after issuing ng server) as,

http://192.168.0.10:4200

Hope this helps!

查看更多
登录 后发表回答