using Microsoft.Extensions.Configuration; using Microsoft.OpenApi.Models; using Serilog; using TelpoKafkaConsole.Model; using TelpoKafkaConsole.Service; using TelpoKafkaConsole.WebApi.Configs; using TelpoKafkaConsole.WebApi.Middleware; namespace TelpoKafkaConsole.WebApi { public class Program { public static void Main(string[] args) { //选择配置文件appsetting.json var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config).Enrich.WithThreadInfo() .CreateLogger(); var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); #region 配置信息 builder.Services .Configure(builder.Configuration.GetSection("ServiceConfig")); #endregion builder.Services.AddSingleton(); builder.Host.UseSerilog(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); } else { var prefix = "kafkaconsole"; app.UseSwagger(c => { c.PreSerializeFilters.Add((swagger, httpReq) => { var scheme = httpReq.Headers.TryGetValue("X-Forwarded-Proto", out var v2) ? v2.ToString() : httpReq.Scheme; swagger.Servers = new List { new OpenApiServer { Url = $"{scheme}://{httpReq.Host}/{prefix}" } }; }); }); } app.UseSwaggerUI(); app.UseAuthorization(); app.UseMiddleware(); app.MapControllers(); app.Run(); } } }