From 34f47edbabd893a3ddb70eb38beda855c4a852a0 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Thu, 23 Nov 2023 18:56:26 -0500 Subject: [PATCH] Nullify `ServerPortProvider` --- .../Core/ServerPortProivder.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/ServerPortProivder.cs b/src/Tgstation.Server.Host/Core/ServerPortProivder.cs index 0b97105c43..a3f39a4ab8 100644 --- a/src/Tgstation.Server.Host/Core/ServerPortProivder.cs +++ b/src/Tgstation.Server.Host/Core/ServerPortProivder.cs @@ -7,8 +7,6 @@ using Microsoft.Extensions.Options; using Tgstation.Server.Host.Configuration; -#nullable disable - namespace Tgstation.Server.Host.Core { /// @@ -36,18 +34,17 @@ namespace Tgstation.Server.Host.Core generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); ArgumentNullException.ThrowIfNull(configuration); + var usingDefaultPort = generalConfiguration.ApiPort == default; + if (!usingDefaultPort) + return; + var httpEndpoint = configuration .GetSection("Kestrel") .GetSection("EndPoints") .GetSection("Http") .GetSection("Url") - .Value; - - if (generalConfiguration.ApiPort == default && httpEndpoint == null) - throw new InvalidOperationException("Missing required configuration option General:ApiPort!"); - - if (generalConfiguration.ApiPort != default) - return; + .Value + ?? throw new InvalidOperationException("Missing required configuration option General:ApiPort!"); logger.LogWarning("The \"Kestrel\" configuration section is deprecated! Please set your API port using the \"General:ApiPort\" configuration option!");