Program.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using SharedKernel;
  2. using Admin.Extensions;
  3. using Admin.Pages.Shared.Layout;
  4. using Admin.Middlewares;
  5. using Application;
  6. using Infrastructure;
  7. var builder = WebApplication.CreateBuilder(args);
  8. var settings = builder.Configuration.Get<AppSettings>()!;
  9. Console.Title = settings.App.Name;
  10. Console.WriteLine($"ENV={builder.Environment.EnvironmentName}");
  11. Console.WriteLine($"현재 시간: {DateTime.Now} / {TimeZoneInfo.Local.Id}");
  12. builder.Host.UseWindowsService();
  13. // Add services to the container.
  14. var mvcBuilder = builder.Services.AddRazorPages(options =>
  15. {
  16. options.Conventions.AuthorizeFolder("/");
  17. options.Conventions.AllowAnonymousToAreaFolder("Identity", "/Account");
  18. });
  19. // 프로그램 설정 값 배치
  20. builder.Services.Configure<AppSettings>(builder.Configuration);
  21. // DB 연결
  22. builder.Services.AddApplication().AddAdminInfrastructure(builder.Configuration);
  23. // 관리자 레이아웃
  24. builder.Services.AddScoped<ILayoutDataProvider, LayoutDataProvider>();
  25. // 인증 및 권한 부여
  26. builder.Services.AddAdminForwardedHeaders(settings); // 리버스 프록시 및 접근 제어
  27. builder.Services.AddAdminIdentity(settings); // 관리자단 Identity 인증 및 비밀번호 정책
  28. builder.Logging.AddConsole(); // 터미널에 로그 출력
  29. if (builder.Environment.IsDevelopment())
  30. {
  31. builder.Logging.AddDebug(); // 디버깅 창에 로그 출력
  32. }
  33. /**
  34. * =======================================================================================================================================================
  35. */
  36. var app = builder.Build();
  37. /**
  38. * =======================================================================================================================================================
  39. */
  40. // 환경변수 불러오기
  41. var env = Environment.GetEnvironmentVariable("environmentVariables");
  42. app.Use(async (context, next) =>
  43. {
  44. context.Items["env"] = env; // 환경변수를 static 변수로 저장
  45. await next();
  46. });
  47. /**
  48. * =======================================================================================================================================================
  49. */
  50. // Configure the HTTP request pipeline.
  51. if (!app.Environment.IsDevelopment())
  52. {
  53. app.UseExceptionHandler("/Error");
  54. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  55. app.UseHsts();
  56. }
  57. app.UseHttpsRedirection();
  58. app.UseRouting();
  59. app.UseAuthentication();
  60. app.UseAuthorization();
  61. // 메뉴 기반 역할 권한 체크
  62. app.UseMiddleware<MenuAuthorizationMiddleware>();
  63. // 관리자 접속 기록
  64. app.UseMiddleware<AdminAccessLogMiddleware>();
  65. app.MapStaticAssets();
  66. app.MapRazorPages().WithStaticAssets();
  67. app.Run();