Refactor Kestrel config and add exception middleware
Replaced "UseKestrelConfig" with "UseCustomKestrelEndpoints" and renamed the "Kestrel" section to "ServerConfig" in both Program.cs and appsettings.json. Updated Kestrel server configuration to use the new section. Added ExceptionHandlingMiddleware to the pipeline for global exception handling.
This commit is contained in:
@@ -3,6 +3,7 @@ using EnvelopeGenerator.Application;
|
||||
using EnvelopeGenerator.Infrastructure;
|
||||
using EnvelopeGenerator.ServiceHost;
|
||||
using EnvelopeGenerator.ServiceHost.Extensions;
|
||||
using EnvelopeGenerator.ServiceHost.Middleware;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Globalization;
|
||||
@@ -15,12 +16,12 @@ if (builder.Configuration.GetValue<bool>("UseWindowsService"))
|
||||
builder.Host.UseWindowsService();
|
||||
}
|
||||
|
||||
if (builder.Configuration.GetValue<bool>("UseKestrelConfig"))
|
||||
if (builder.Configuration.GetValue<bool>("UseCustomKestrelEndpoints"))
|
||||
{
|
||||
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
|
||||
{
|
||||
var kestrelSection = context.Configuration.GetSection("Kestrel");
|
||||
serverOptions.Configure(kestrelSection);
|
||||
var serverConfigSection = context.Configuration.GetSection("ServerConfig");
|
||||
serverOptions.Configure(serverConfigSection);
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
@@ -65,6 +66,8 @@ builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user