From aed40398b82950bd0107fcac1b0cce53d156f22f Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 28 Feb 2026 10:46:48 -0500 Subject: [PATCH] Bind public gateway port explicitly --- Server/src/SOR.Host/Program.cs | 39 ++++------------------------------ 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/Server/src/SOR.Host/Program.cs b/Server/src/SOR.Host/Program.cs index 808b651..3e4a6ee 100644 --- a/Server/src/SOR.Host/Program.cs +++ b/Server/src/SOR.Host/Program.cs @@ -29,8 +29,6 @@ using Serilog; using StackExchange.Redis; using NATS.Client.Core; using NATS.Client.Hosting; -using System.Net; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.WebSockets; using Microsoft.AspNetCore.Server.Kestrel.Core; using SOR.Auth.Handlers; @@ -60,27 +58,19 @@ var builder = WebApplication.CreateBuilder(args); // Auth gRPC calls are internal-only and should not share the public WebSocket listener. // When auth is co-located with gateway and Services:Auth points at a loopback HTTP URL, -// preserve the existing HTTP listeners explicitly and add a dedicated HTTP/2 loopback +// explicitly bind the public HTTP/WebSocket port and add a dedicated HTTP/2 loopback // listener for gRPC on the configured auth port. if (IsEnabled("auth") && Uri.TryCreate(builder.Configuration["Services:Auth"], UriKind.Absolute, out var authServiceUri) && string.Equals(authServiceUri.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) && authServiceUri.IsLoopback) { - var configuredUrls = builder.WebHost.GetSetting(WebHostDefaults.ServerUrlsKey) - ?? builder.Configuration["ASPNETCORE_URLS"]; - builder.WebHost.ConfigureKestrel(options => { - foreach (var rawUrl in (configuredUrls ?? string.Empty).Split( - ';', - StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + options.ListenAnyIP(8080, listenOptions => { - if (!Uri.TryCreate(rawUrl, UriKind.Absolute, out var configuredUri)) - continue; - - ListenOnConfiguredUrl(options, configuredUri); - } + listenOptions.Protocols = HttpProtocols.Http1; + }); options.ListenLocalhost(authServiceUri.Port, listenOptions => { @@ -220,24 +210,3 @@ Log.Information("SOR Host starting. Services: {Services}", rawServices); // On shutdown, ASP.NET Core calls StopAsync on all IHostedService implementations // (including GatewayHostedService) in reverse registration order. await app.RunAsync(); - -static void ListenOnConfiguredUrl(KestrelServerOptions options, Uri uri) -{ - if (!string.Equals(uri.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase)) - return; - - if (uri.Host == "+" || uri.Host == "*" || uri.Host == "0.0.0.0") - { - options.ListenAnyIP(uri.Port, listenOptions => listenOptions.Protocols = HttpProtocols.Http1); - return; - } - - if (string.Equals(uri.Host, "localhost", StringComparison.OrdinalIgnoreCase)) - { - options.ListenLocalhost(uri.Port, listenOptions => listenOptions.Protocols = HttpProtocols.Http1); - return; - } - - if (IPAddress.TryParse(uri.Host, out var ipAddress)) - options.Listen(ipAddress, uri.Port, listenOptions => listenOptions.Protocols = HttpProtocols.Http1); -}