11

I've done lost of search for couple of hours now and still can't find what I'm looking for. Basically I get this error in the console when running ng serve in my Angular 6 app:

GET http://local.mywebsitesecure.com/sockjs-node/info?t=1540568455931 404 (Not Found)

Based on my research the solution could be just updating

webpack.config.js

However, I can't find webpack.config.js in my project. They also say to do:

"ng eject"

to create a webpack, but it doesn't seem to work.

SOLUTION: I can get it to work by running this (It actually works!):

ng serve --public-host=http://localhost:4200

BUT I want to be able to set this up somewhere in my app so that I can only do

ng serve

Does anyone know how to fix this issue and gid rid of this error (sockjs-node/info). Thanks a lot in advance!

Devmix
  • 1,599
  • 5
  • 36
  • 73

1 Answers1

17

You can edit your angular.json file and add the option for public-host. Mind you all options are camelCased not kebab-cased.

...
"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "browserTarget": "congiftest:build",
    "publicHost":"http://localhost:4200"
  },
},
...

This will allow you to just run ng serve and the public-host flag will be added.

Sergej
  • 1,082
  • 11
  • 27
Niles Tanner
  • 3,911
  • 2
  • 17
  • 29
  • 2
    Have you tried this on .Net core - I've tried Https://localhost:5001/subfolder/ and it's still broken - I have tried many variations - any ideas? I have tried both as a parameter and in angular.json. I have my app being served inside a sub-folder. – DanAbdn Oct 28 '18 at 18:20
  • @progx not at the moment, I was mostly answering your second question. – Niles Tanner Oct 28 '18 at 19:09
  • Is not there a typo? congiftest:build – Leos Literak Mar 22 '20 at 13:40
  • 1
    Note to my future self and any googlers: It seems like angular 11 has changed the behavior of the port when the application is proxied. Instead of the proxy-port, now the port specified on the command line (--port or the default) is used. So anyone who develops through a reverse proxy now has to define the public host for any port different than 4200. – 1FpGLLjZSZMx6k Nov 17 '20 at 15:32