Updated ng-cli with working draft now "Can not GET /"?

I had a working cli project that was built with the beta.21 version of the cli. I wanted to update it to use the latest cli project structure, so I created a new project with cli ( v.1.0.0 ). Then I essentially put the contents of my existing project app file into a new project and went from there.

Strange, but my new project builds seamlessly and produces the sizes and chunks that I expected. If I run an express based backend that serves the contents of a directory ./dist

, then my application works as expected. However, if I run ng serve

I get an error Cannot GET /

in the browser.

I'm really not sure what might have caused this (my biggest suspicion is that my project has a file structure with client/src/app

and not the default one src/app

, however I changed all references to the file path I could find and how the build works, I guess it's good)?

Any ideas / suggestions for further debugging?

Update:

client/src/index.html

:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>DemoProj</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root>Loading...</app-root>
</body>
</html>

      

.angular-cli.json

:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "coty-monitoring-system"
  },
  "apps": [
    {
      "root": "client/src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [
        "../../node_modules/chart.js/dist/Chart.bundle.js",
        "../../node_modules/hammerjs/hammer.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "client/src/tsconfig.app.json"
    },
    {
      "project": "client/src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

      

failed request browser network tab:

enter image description here

Here is the page source of what the cli returns:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>

      

+3


source to share


2 answers


Seems wonderful. You may not have started ng serve

in your project folder.

When using the CLI, you need to run ng serve

where app.module.ts is located ** usually:



$ projectFolder \ src \ app

+4


source


You can also get this problem if ng serve

from a subfolder deeper inside the project folder. I just created a new component and forgot to go back to the project root before ng serve

. As a result, I got a 404 "Can't GET / "./ P>



0


source







All Articles