Program.cs 2.4 KB

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