From 0661dbe3886a9cbeac433b17f61e1d8abc6b3e83 Mon Sep 17 00:00:00 2001 From: GZTime Date: Thu, 8 Feb 2024 22:16:36 +0800 Subject: [PATCH] fix: add `Bind` for kestrel config --- src/GZCTF/Program.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/GZCTF/Program.cs b/src/GZCTF/Program.cs index d39d076b4..b43bacb83 100644 --- a/src/GZCTF/Program.cs +++ b/src/GZCTF/Program.cs @@ -50,7 +50,9 @@ builder.WebHost.ConfigureKestrel(options => { - options.Configure(builder.Configuration.GetSection("Kestrel")); + var kestrelSection = builder.Configuration.GetSection("Kestrel"); + options.Configure(kestrelSection); + kestrelSection.Bind(options); }); builder.Logging.ClearProviders(); @@ -131,14 +133,10 @@ #endregion OpenApiDocument -#region SignalR +#region SignalR & Cache ISignalRServerBuilder signalrBuilder = builder.Services.AddSignalR().AddJsonProtocol(); -#endregion SignalR - -#region Cache - var redisConStr = builder.Configuration.GetConnectionString("RedisCache"); if (string.IsNullOrWhiteSpace(redisConStr)) { @@ -157,7 +155,7 @@ }); } -#endregion Cache +#endregion SignalR & Cache #region Identity @@ -243,8 +241,6 @@ builder.Services.AddHostedService(); builder.Services.AddHostedService(); -#endregion Services and Repositories - builder.Services.AddHealthChecks(); builder.Services.AddRateLimiter(RateLimiter.ConfigureRateLimiter); builder.Services.AddResponseCompression(options => @@ -261,14 +257,18 @@ options.InvalidModelStateResponseFactory = GZCTF.Program.InvalidModelStateHandler; }); -WebApplication app = builder.Build(); +#endregion Services and Repositories -app.UseRequestLocalization(); +#region Middlewares + +WebApplication app = builder.Build(); Log.Logger = LogHelper.GetLogger(app.Configuration, app.Services); await app.RunPrelaunchWork(); +app.UseRequestLocalization(); + app.UseResponseCompression(); app.UseStaticFiles(new StaticFileOptions @@ -315,6 +315,8 @@ app.MapFallbackToFile("index.html"); +#endregion Middlewares + await using AsyncServiceScope scope = app.Services.CreateAsyncScope(); var logger = scope.ServiceProvider.GetRequiredService>();