From 3e636dfca3bb2c5c35d3dbc7c2a531b53a5df177 Mon Sep 17 00:00:00 2001 From: Xeon Date: Sun, 30 Jun 2024 17:42:32 +0800 Subject: [PATCH] Fix streamflow not connecting to local servers --- .../Services/SignalRService.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/XFramework.Integration/Services/SignalRService.cs b/src/Infrastructure/XFramework.Integration/Services/SignalRService.cs index f15e2392..5e189ec3 100644 --- a/src/Infrastructure/XFramework.Integration/Services/SignalRService.cs +++ b/src/Infrastructure/XFramework.Integration/Services/SignalRService.cs @@ -63,9 +63,23 @@ private void InitializeService() _logger.LogWarning("StreamFlow configuration is not set, therefore SignalR client service is disabled"); return; } - + + var serverUrl = StreamFlowConfiguration?.ServerUrls?.FirstOrDefault() ?? new Uri(envConfig); Connection = new HubConnectionBuilder() - .WithUrl(StreamFlowConfiguration?.ServerUrls?.FirstOrDefault() ?? new Uri(envConfig)) + .WithUrl(serverUrl, (opts) => + { + if (serverUrl.AbsoluteUri.StartsWith("https://localhost", StringComparison.OrdinalIgnoreCase) + || serverUrl.AbsoluteUri.StartsWith("https://127.0.0.1", StringComparison.OrdinalIgnoreCase)) + { + opts.HttpMessageHandlerFactory = (message) => + { + if (message is HttpClientHandler clientHandler) + // always verify the SSL certificate + clientHandler.ServerCertificateCustomValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; + return message; + }; + } + }) .WithAutomaticReconnect(Enumerable.Repeat(TimeSpan.FromSeconds(2), 2000).ToArray()) .AddMessagePackProtocol() .Build();