|
- 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<ServiceConfig>(builder.Configuration.GetSection("ServiceConfig"));
- #endregion
-
-
- builder.Services.AddSingleton<KafkaAdminService>();
-
-
-
- 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<OpenApiServer> { new OpenApiServer { Url = $"{scheme}://{httpReq.Host}/{prefix}" } };
- });
- });
- }
-
- app.UseSwaggerUI();
-
-
-
- app.UseAuthorization();
-
- app.UseMiddleware<LoggingMiddleware>();
-
- app.MapControllers();
-
- app.Run();
- }
- }
- }
|