Program.cs 2.6 KB

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