Skip to content

Angular 15: webpack dev server websocket URL should use port number specified in config instead of hardcoding 0 #24373

@prabh-62

Description

@prabh-62

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When serving angular 15 application behind a reverse proxy on different port, webpack dev server fails to live-reload.

Specifically, this line of code should use options.port rather than hardcoding 0
[dev-server.ts#L333](

return `auto://${publicHost || '0.0.0.0:0'}${webSocketPath}`;
)
should become

    return `${options.sslKey === undefined ? 'ws': 'wss'}://${publicHost || options.host}:${options.port}${webSocketPath}`;

Minimal Reproduction

  • Create an angular 15 application
    • Serve the app : ng serve --project teddyBear --port 4201
  • Launch a reverse proxy which serves on different host and/or port and just returns the angular 15 app files.
    • Even though the angular app might serve, live-reload should fail

webpack_ws_fails_no_port

Exception or Error

[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading enabled, Progress disabled, Overlay enabled.
WebSocket connection to 'ws://localhost/ng-cli-ws' failed: 
[webpack-dev-server] Trying to reconnect...

Your Environment

Angular CLI: 15.0.2
Node: 18.12.1
Package Manager: yarn 1.22.19
OS: darwin arm64

Angular: 15.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.2
@angular-devkit/build-angular   15.0.2
@angular-devkit/core            15.0.2
@angular-devkit/schematics      15.0.2
@angular/cdk                    15.0.1
@schematics/angular             15.0.2
ng-packagr                      15.0.1
rxjs                            7.5.7
typescript                      4.8.4

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions