Files
taxbaik/TaxBaik.Admin/Program.cs
T
kjh2064 e7e01d0cd8
TaxBaik CI/CD / build-and-deploy (push) Failing after 15s
마이그레이션 및 보안 수정
- MigrationRunner: 이미 존재하는 테이블에 대한 "relation already exists" 오류 처리
- V002, V003 마이그레이션: ON CONFLICT DO NOTHING으로 멱등성 보장
- Web, Admin Program.cs: app.UseAntiforgery() 미들웨어 추가 (anti-forgery 토큰 검증)

변경사항:
- 마이그레이션 재실행 시에도 안전하게 처리
- 폼 제출 시 CSRF 공격 방지
- 관리자 로그인 페이지 405 에러 해결

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-26 16:46:36 +09:00

53 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Authentication.Cookies;
using MudBlazor.Services;
using TaxBaik.Application;
using TaxBaik.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(opts => {
opts.LoginPath = "/login";
opts.ExpireTimeSpan = TimeSpan.FromHours(8);
opts.Cookie.SameSite = SameSiteMode.Lax;
});
builder.Services.AddAuthorizationCore();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddMudServices();
builder.Services.AddMemoryCache();
builder.Services.AddInfrastructure();
builder.Services.AddApplication();
var app = builder.Build();
// Run migrations on startup
using (var scope = app.Services.CreateScope())
{
var connectionFactory = scope.ServiceProvider.GetRequiredService<TaxBaik.Domain.Interfaces.IDbConnectionFactory>();
var cs = builder.Configuration.GetConnectionString("Default")
?? throw new InvalidOperationException("Missing connection string");
var migrationRunner = new TaxBaik.Infrastructure.Data.MigrationRunner(cs, connectionFactory);
await migrationRunner.RunAsync();
}
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UsePathBase("/taxbaik/admin");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseAntiforgery();
app.MapRazorComponents<TaxBaik.Admin.Components.App>()
.AddInteractiveServerRenderMode();
app.Run();