From 355d9853496aa5db6db0e116c9bb38c559f9a7ac Mon Sep 17 00:00:00 2001 From: Archangel Date: Thu, 20 Feb 2025 15:19:50 +0100 Subject: [PATCH] Slight refactor to webserver init --- Libraries/Core/Servers/HttpServer.cs | 15 ++++----------- Server/Program.cs | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Libraries/Core/Servers/HttpServer.cs b/Libraries/Core/Servers/HttpServer.cs index 13e040ef..9147d998 100644 --- a/Libraries/Core/Servers/HttpServer.cs +++ b/Libraries/Core/Servers/HttpServer.cs @@ -1,14 +1,11 @@ using System.Net; using System.Security.Authentication; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; using Core.Context; using Core.Helpers; using Core.Models.Spt.Config; using Core.Models.Utils; using Core.Servers.Http; using Core.Services; -using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.Extensions.Primitives; using SptCommon.Annotations; @@ -35,19 +32,15 @@ public class HttpServer( { throw new Exception("WebApplicationBuilder is null in HttpServer.Load()"); } - builder.Services.AddHttpsRedirection(conf => - { - conf.HttpsPort = _httpConfig.Port; - }); + builder.WebHost.ConfigureKestrel( options => { - options.ListenAnyIP(_httpConfig.Port, listenOptions => + options.Listen(IPAddress.Parse(_httpConfig.Ip), _httpConfig.Port, listenOptions => { listenOptions.UseHttps(opts => { - opts.SslProtocols = SslProtocols.Tls12; - opts.AllowAnyClientCertificate(); + opts.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13; opts.ServerCertificate = _certificateHelper.LoadOrGenerateCertificatePfx(); opts.ClientCertificateMode = ClientCertificateMode.NoCertificate; }); @@ -55,7 +48,7 @@ public class HttpServer( }); var app = builder.Build(); - app.UseHttpsRedirection(); + if (app is null) { throw new Exception("WebApplication is null in HttpServer.Load()"); diff --git a/Server/Program.cs b/Server/Program.cs index 9f35ff80..48179831 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -63,7 +63,7 @@ public static class Program // object, which we can use here to start the webapp. if (httpServerHelper != null) { - appContext?.GetLatestValue(ContextVariableType.WEB_APPLICATION)?.GetValue().Run(httpServerHelper.GetBackendUrl()); + appContext?.GetLatestValue(ContextVariableType.WEB_APPLICATION)?.GetValue().Run(); } } catch (Exception ex)