4

As I understand when running ng serve the Angular app polls the dev server to find out if a reload is necessary. This server is expected to live on port 4200 (default).

I run a dev environment with multiple docker container to keep things nice and isolated. So some of my angular apps listen on different ports. This seems to lead to the following error message appearing in my browser console every couple of seconds:

zone.js:2744 GET http://localhost:4200/sockjs-node/info?t=1518533495440 net::ERR_EMPTY_RESPONSE

Where can I change the configuration to point the live reload client in the correct direction? angular-cli.json doesn't seem to do anything.

Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160

5 Answers5

8

I found the solution. You have to start ng serve with the --public-host option (aliases: --live-reload-client). So I adapted my start command in the package.json from

"start": "ng serve --host 0.0.0.0"

to

"start": "ng serve --host 0.0.0.0 --live-reload-client http://localhost:4400"

The whole point is that I don't want to change the port of the dev server itself. It should run inside the Docker container on port 4200. But port 4200 is mapped in Docker to the outside port 4400 (in my case). I call http://localhost:4400 to run the app in my browser and the reload client should also call http://localhost:4400 for updates. But it called http://localhost:4200. With the --live-reload-client option everything works.

Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
  • this worked for me `ng serve --public-host http://localhost:4200`. URL in the adress bar is 9090 which proxies to 4200 (but can't proxy websockets) – Rivenfall May 10 '19 at 14:44
  • At least from now (august 2022), it seems that the "live-reload-client" alias doesn't exist anymore as the previous command returns "Error: Unknown argument: live-reload-client". Fortunately, it works with "public-host". – Tristan CHARBONNIER Aug 12 '22 at 00:02
1

You can configure the default HTTP port and the one used by the LiveReload server with two command-line options :

ng serve --host 0.0.0.0 --port 4201 --live-reload-port 49153
santosh singh
  • 27,666
  • 26
  • 83
  • 129
0

It seems --live-reload-port is no longer used in newer versions. Live reload port is identical to development server port. So setting --port 4201 will use 4201 as the live reload port.

nandithakw
  • 989
  • 11
  • 16
-1

You can change the port using --port

ng serve --port 4201

Will start the server on port 4201

void
  • 36,090
  • 8
  • 62
  • 107
  • I don't want to change the port of the app itself. It runs internally inside the docker container on 4200 but that is mapped to port 4400 on the outside. That is what creates this issue in the first place. – Ole Spaarmann Feb 13 '18 at 15:10
-1

While running your application instance use this command: ng serve --port 123

instead of: ng serve

whilst changing in package.json doesn't make any impact.