Angular 15: webpack dev server websocket URL should use port number specified in config instead of hardcoding 0
See original GitHub issueCommand
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](https://github.com/angular/angular-cli/blob/cf2f30afc0ad0ceae34c457955a22186bc5ce60d/packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts#L333)
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
- Serve the app :
- 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
- Even though the angular app might serve, live-reload should fail
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
Issue Analytics
- State:
- Created 10 months ago
- Comments:9
Top Results From Across the Web
WebSocket connection to 'ws://localhost:3000/ws' failed: #11779
Basic React App doesn't work because the websocket connection appears to be hardcoded to port 3000. Part of this appears to be related...
Read more >webpack-dev-server error after migrating to Angular 13
I had the same issue and was able to resolve it by using --public-host while serving the app. E.g. if your app is...
Read more >Firebase JavaScript SDK Release Notes - Google
Fixed issue where clients using Node.js v18 would use the native Blob ... The SDK can now infer a default database URL if...
Read more >How To Use Custom webpack Configurations with Angular ...
Learn how to create a custom webpack config inside an Angular project using CLI Builders. This example will reduce the file size of...
Read more >Changelog | Meteor API Docs
needs to use directly from npm the meteorjs/babel@7.16.1-beta.0. Breaking Changes. N/A. Migration Steps. Meteor Version Release. mongo@1.16.2 :.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem here is that you have two applications using the same Websocket path (
ws://localhost/ng-cli-ws
) which causes a conflict.In this case you need to configure the the dev-server using the
serve-path
option so that each application gets a dedicated WS path.The proxy will then need to be adjusted to cater for the serve paths by removing the path rewrites.
This should also address the comment in https://github.com/microsoft/reverse-proxy/discussions/1954#discussioncomment-4329533.
Based on your proxy setup you might also end up using the
public-host
option. See: https://angular.io/cli/serve for more information about the dev-server options.Closing this issue as there does not appear to be a bug here. This issue tracker is not suitable for support, please repost your issue on StackOverflow using tag
angular-cli
.Thank you for the suggestion. This is exactly what I was looking for