From 6580ac27b88c3a0b65f7ff32bae0bc8192a155a5 Mon Sep 17 00:00:00 2001 From: "Seonkyu.kim" Date: Tue, 20 May 2025 09:47:38 +0900 Subject: [PATCH] =?UTF-8?q?[=E2=99=BB=EF=B8=8F]=20=EA=B0=9C=EB=B0=9C=20FRO?= =?UTF-8?q?NT=20=ED=99=94=EB=A9=B4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/Program.cs b/Program.cs index be45394..3ec6062 100644 --- a/Program.cs +++ b/Program.cs @@ -24,6 +24,9 @@ using Back.Program.Services.V1; using Back.Program.Services.V1.Interfaces; +Boolean isLocal = false; +// 로컬 테스트 할 때는 이거 키고 아니면 끄기 +isLocal = true; var builder = WebApplication.CreateBuilder(args); @@ -32,8 +35,6 @@ var builder = WebApplication.CreateBuilder(args); builder.Configuration.AddJsonFile("private/dbSetting.json", optional: true, reloadOnChange: true); builder.Services.AddHttpContextAccessor(); -// var connectionString = builder.Configuration.GetConnectionString("MariaDbConnection"); -// builder.Services.AddDbContext(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))); builder.Services.AddDbContext(optionsAction: (serviceProvider, options) => { var httpContextAccessor = serviceProvider.GetRequiredService(); @@ -102,8 +103,6 @@ builder.Services.AddHttpClient(client => { var config = builder.Configuration.GetSection("PushFileSetting").Get(); var handler = new HttpClientHandler(); - // using var reader = new StreamReader(config.p12PWPath, new UTF8Encoding(false)); - // var json = reader.ReadToEndAsync(); // p12PWPath 파일에서 비밀번호 읽어오기 (예시: JSON {"Password": "비밀번호"}) var json = File.ReadAllText(config.p12PWPath); var keys = JsonSerializer.Deserialize>(json); @@ -120,6 +119,7 @@ builder.Services.AddHostedService(); builder.Services.AddControllers(); +// ==== SCOPED 으로 등록 할 서비스 ==== // // 여기다가 API 있는 컨트롤러들 AddScoped 하면 되는건가? builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -161,40 +161,44 @@ builder.Services.AddCors(option => // 로그 설정 부분 builder.Logging.ClearProviders(); builder.Logging.AddConsole(); -if (builder.Environment.IsDevelopment()) { - builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.SetMinimumLevel(builder.Environment.IsDevelopment() ? LogLevel.Trace : LogLevel.Warning); + +if (isLocal) +{ + builder.WebHost.UseUrls("http://0.0.0.0:5144"); } else { - builder.Logging.SetMinimumLevel(LogLevel.Warning); + builder.WebHost.UseUrls(builder.Environment.IsDevelopment()? "http://0.0.0.0:7004":"http://0.0.0.0:7003"); } - -builder.WebHost.UseUrls("http://0.0.0.0:7004"); - - -// 로컬 테스트 위한 부분 (올릴때는 꺼두기) -// builder.WebHost.UseUrls("http://0.0.0.0:5144"); - ///// ===== builder 설정 부 ===== ///// var app = builder.Build(); + string staticRoot; +if (isLocal) +{ + staticRoot = app.Environment.IsDevelopment() ? + Path.Combine(Directory.GetCurrentDirectory(), "publish", "debug", "wwwroot") : + Path.Combine(Directory.GetCurrentDirectory(), "publish", "release", "wwwroot") ; +} +else +{ + staticRoot = app.Environment.IsDevelopment() ? + "/src/publish/debug/wwwroot" : "/src/publish/release/wwwroot" ; +} if (app.Environment.IsDevelopment()) { - // app.UseSwagger(); - // app.UseSwaggerUI(); app.UseCustomSwaggerUI(); app.UseDeveloperExceptionPage(); // 좀더 자세한 예외 정보 제공 - staticRoot = Path.Combine(Directory.GetCurrentDirectory(), "publish", "debug", "wwwroot"); } else { app.UseExceptionHandler("/error"); app.UseHsts(); - staticRoot = Path.Combine(Directory.GetCurrentDirectory(), "publish", "release", "wwwroot"); } // 로컬 테스트 위한 부분 (올릴떄는 켜두기) @@ -203,12 +207,8 @@ app.UseHttpsRedirection(); //예외처리 미들웨어 부분 app.UseMiddleware(); // 헤더 미들웨어 부분 -app.UseMiddleware( - (object)new string[] { "iOS_AM_Connect_Key", "And_AM_Connect_Key", "Web_AM_Connect_Key" } - ); - -// app.UseBlazorFrameworkFiles(); -// app.UseStaticFiles(); +app.UseMiddleware + ((object)new string[] { "iOS_AM_Connect_Key", "And_AM_Connect_Key", "Web_AM_Connect_Key" }); app.UseStaticFiles(new StaticFileOptions { @@ -216,9 +216,6 @@ app.UseStaticFiles(new StaticFileOptions RequestPath = "" }); - - - app.UseRouting(); app.UseCors("CorsPolicy"); app.UseAuthorization(); @@ -228,10 +225,7 @@ app.UseWebSockets(); app.UseEndpoints(end => { ControllerEndpointRouteBuilderExtensions.MapControllers(end); - - // 프론트 테스트 위한 부분 end.MapFallbackToFile("index.html"); - end.MapHub("/chatHub"); });