using Microsoft.Extensions.DependencyInjection.Extensions; using minattest_app_host.OpenApi; using Serilog; using Yarp.ReverseProxy.Forwarder; Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .CreateBootstrapLogger(); try { Log.Information("Starting minattest app host"); var builder = WebApplication.CreateBuilder(args); builder.Host.UseSerilog((context, services, configuration) => configuration .ReadFrom.Configuration(context.Configuration) .ReadFrom.Services(services)); builder.Services.AddReverseProxy() .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwagger(); builder.Services.TryAddSingleton(); var app = builder.Build(); app.UseSerilogRequestLogging(); app.Use((context, next) => { context.Request.Scheme = "https"; return next(context); }); app.UseAppSwagger(); app.UseHttpsRedirection(); app.MapReverseProxy(configure => configure.Use(async (context, next) => { await next(); var errorFeature = context.GetForwarderErrorFeature(); if (errorFeature is not null && errorFeature.Error != ForwarderError.None && errorFeature.Exception != null) throw errorFeature.Exception; })); app.Run(); } catch (Exception ex) { Log.Fatal(ex, "Application terminated unexpectedly"); } finally { Log.CloseAndFlush(); }