using Microsoft.OpenApi.Models; using Microsoft.AspNetCore.HttpOverrides; using System.Net; using log4net; using Coravel; using AipDatabase.API.Repositories; using AipDatabase.API.Interfaces; using AipDatabase.API.Scheduler; using AipDatabase.API.Middlewares; using Dapper; using AipDatabase.API.Infrastructures; internal class Program { private static readonly log4net.ILog _log = LogManager.GetLogger(typeof(Program)); private static void Main(string[] args) { try { var builder = WebApplication.CreateBuilder(args); builder.Logging.ClearProviders(); builder.Logging.AddLog4Net(); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != null) { _log.InfoFormat("Start AIP Database RESTFull API Service... [{0}]", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")); } else { _log.Info("Start AIP Database RESTFull API Service..."); } ConfigureSettings(builder.Host, builder.Environment); // ȯ°æ¼³Á¤ ÆÄÀÏ ¼³Á¤ builder.Services.AddControllers(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "AIP Database RESTFull API Service", Version = "v1" }); }); builder.Services.Configure(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; options.KnownNetworks.Clear(); options.KnownProxies.Clear(); }); int Port = 9872; if (!int.TryParse(builder.Configuration["Port"], out Port)) { Port = 9873; } builder.WebHost.ConfigureKestrel((context, serverOptions) => { //serverOptions.Limits.MaxRequestBodySize = 100_000_000; // [RequestSizeLimit(100_000_000)] --> Controller À§¿¡ ¼±¾ð, IHttpMaxRequestBodySizeFeature //serverOptions.Limits.MaxConcurrentConnections = 100; //serverOptions.Limits.MaxConcurrentUpgradedConnections = 100; serverOptions.Listen(IPAddress.Any, Port, listenOptions => { //listenOptions.UseHttps("testCert.pfx", "testPassword"); //listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3; }); }); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); //builder.Services.AddScoped(); builder.Services.AddScoped(); // Scheduler Job //builder.Services.AddScheduler(); //builder.Services.AddTransient(); builder.Services.AddHealthChecks(); builder.Services.AddCors(p => p.AddPolicy("corsapp", builder => { //builder.WithOrigins("*", "http://localhost:3011", "https://localhost:3011", "https://localhost:7261").AllowAnyMethod().AllowAnyHeader(); })); var app = builder.Build(); //app.Services.UseScheduler(scheduler => //{ // scheduler.OnWorker("AipDatabaseSchedulerTask"); // scheduler.Schedule() // .Hourly(); //}); app.UseHsts(); app.UseHttpsRedirection(); //app.UseStaticFiles(); app.UseRouting(); app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseCors("corsapp"); app.UseAuthentication(); app.UseAuthorization(); app.UseMiddleware(); app.UseHealthChecks("/health"); //if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "AIP Database API v1"); options.RoutePrefix = "swagger-ui"; }); } app.MapControllers(); app.Run(); } catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" && ex.GetType().Name is not "HostAbortedException") { _log.FatalFormat("Program Unhandled exception: {ex}"); } finally { _log.Info("Shut down complete"); } } private static void ConfigureSettings(IHostBuilder hostBuilder, IHostEnvironment environment) { hostBuilder.ConfigureAppConfiguration(config => { config .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile( path: "appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile( path: $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); }); } }