Why is the SignalR client(@microsoft/signalr) seems like trying to connect to the root URL instead of only what I supplied? #57479
-
My set-up is both the angular app(no .NET) and my ASP.NET Core(.NET 8.0) Web API are behind nginx which serves as reverse proxy. I mapped the SignalR hubs in /hub/ in Nginx. In the Angular side, I only have one service for this import { Injectable } from '@angular/core';
import * as signalR from '@microsoft/signalr';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class AppSignalRService {
private hubConnection: signalR.HubConnection;
constructor() {
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl('/hub/realtimehub') // SignalR hub URL
.build();
}
startConnection(): Observable<void> {
return new Observable<void>((observer) => {
this.hubConnection
.start()
.then(() => {
console.log('Connection established with SignalR hub');
observer.next();
observer.complete();
})
.catch((error: any) => {
console.error('Error connecting to SignalR hub:', error);
observer.error(error);
});
});
}
receiveMessage(): Observable<string> {
return new Observable<string>((observer) => {
this.hubConnection.on('ReceiveMessage', (message: string) => {
observer.next(message);
});
});
}
sendMessage(message: string): void {
this.hubConnection.invoke('SendMessage', message);
}
} All 3 applications are running through Docker. Both Angular and Web API aren't exposed, only through Nginx. The Angular app is running on Port 4200 and Web API on 8080 in their own containers. I can connect properly to the hub and it works fine. But I'm bothered with the log that it says Here is the log
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @eSPiYa, |
Beta Was this translation helpful? Give feedback.
Hi @eSPiYa,
I don't think those
wss://localhost
andwss://localhost:4200
errors are from SignalR, they’re probraly from the Angular dev server’s HMR client trying to open a WebSocket to refresh the page when code changes.Since your app is served behind Nginx in Docker and not directly from the dev server, those connections fail but they don’t affect your SignalR hub (which is already connecting fine to
/hub/realtimehub
).In a production build, the HMR client isn’t included, so the warnings disappear. You shiuld try to disable the live reload in dev enviroment to test.