using Microsoft.EntityFrameworkCore; using SPMS.API.Middlewares; using SPMS.Domain.Interfaces; using SPMS.Infrastructure; using SPMS.Infrastructure.Persistence; using SPMS.Infrastructure.Persistence.Repositories; var builder = WebApplication.CreateBuilder(new WebApplicationOptions { WebRootPath = Environment.GetEnvironmentVariable("ASPNETCORE_WEBROOT") ?? "wwwroot" }); builder.Services.AddControllers(); builder.Services.AddOpenApi(); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))); builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); builder.Services.AddScoped(); var app = builder.Build(); // ── 1. 예외 처리 (최외곽 — 이후 모든 미들웨어 예외 포착) ── app.UseMiddleware(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } var webRoot = app.Environment.WebRootPath; Console.WriteLine($"[System] Web Root Path: {webRoot}"); // 로그에 경로 찍어보기 if (Directory.Exists(webRoot)) { app.UseStaticFiles(); // 경로가 있으면 파일 서빙 } else { Console.WriteLine("[Error] Web root folder not found!"); } app.UseHttpsRedirection(); app.UseRouting(); // [4] 요청 처리 app.MapControllers(); app.MapFallbackToFile("index.html"); app.Run();