Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

83 lines
2.3KB

  1. using Microsoft.Extensions.Configuration;
  2. using Microsoft.OpenApi.Models;
  3. using Serilog;
  4. using TelpoKafkaConsole.Model;
  5. using TelpoKafkaConsole.Service;
  6. using TelpoKafkaConsole.WebApi.Configs;
  7. using TelpoKafkaConsole.WebApi.Middleware;
  8. namespace TelpoKafkaConsole.WebApi
  9. {
  10. public class Program
  11. {
  12. public static void Main(string[] args)
  13. {
  14. //Ñ¡ÔñÅäÖÃÎļþappsetting.json
  15. var config = new ConfigurationBuilder()
  16. .SetBasePath(Directory.GetCurrentDirectory())
  17. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  18. .Build();
  19. Log.Logger = new LoggerConfiguration()
  20. .ReadFrom.Configuration(config).Enrich.WithThreadInfo()
  21. .CreateLogger();
  22. var builder = WebApplication.CreateBuilder(args);
  23. // Add services to the container.
  24. builder.Services.AddControllers();
  25. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  26. builder.Services.AddEndpointsApiExplorer();
  27. builder.Services.AddSwaggerGen();
  28. #region ÅäÖÃÐÅÏ¢
  29. builder.Services
  30. .Configure<ServiceConfig>(builder.Configuration.GetSection("ServiceConfig"));
  31. #endregion
  32. builder.Services.AddSingleton<KafkaAdminService>();
  33. builder.Host.UseSerilog();
  34. var app = builder.Build();
  35. // Configure the HTTP request pipeline.
  36. if (app.Environment.IsDevelopment())
  37. {
  38. app.UseSwagger();
  39. }
  40. else
  41. {
  42. var prefix = "kafkaconsole";
  43. app.UseSwagger(c =>
  44. {
  45. c.PreSerializeFilters.Add((swagger, httpReq) =>
  46. {
  47. var scheme = httpReq.Headers.TryGetValue("X-Forwarded-Proto", out var v2) ? v2.ToString() : httpReq.Scheme;
  48. swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = $"{scheme}://{httpReq.Host}/{prefix}" } };
  49. });
  50. });
  51. }
  52. app.UseSwaggerUI();
  53. app.UseAuthorization();
  54. app.UseMiddleware<LoggingMiddleware>();
  55. app.MapControllers();
  56. app.Run();
  57. }
  58. }
  59. }