diff --git a/GermanApp/Program.cs b/GermanApp/Program.cs index 3321396..8c64b0f 100644 --- a/GermanApp/Program.cs +++ b/GermanApp/Program.cs @@ -91,17 +91,29 @@ try // Configure CORS builder.Services.AddCors(options => { + // AllowAll policy - for production without credentials + // Note: Cannot use AllowAnyOrigin() with AllowCredentials() options.AddPolicy("AllowAll", builder => { builder.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader(); + // Note: No AllowCredentials() - cannot combine with AllowAnyOrigin() + }); + + // Development policy - for Docker and local development with credentials + options.AddPolicy("Development", builder => + { + builder.WithOrigins("http://localhost:5173", "http://localhost:5174", "http://localhost:5175", "http://localhost:3000") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); - options.AddPolicy("Development", builder => + // Docker policy - for when frontend is served from Docker nginx + options.AddPolicy("Docker", builder => { - builder.WithOrigins("http://localhost:5173", "http://localhost:5174", "http://localhost:5175", "http://localhost:3000") + builder.WithOrigins("http://localhost:3000") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); @@ -255,7 +267,9 @@ try app.UseExceptionMiddleware(); // Use CORS - must be early in the pipeline, before UseAuthorization - app.UseCors("AllowAll"); + // In Docker, use "Docker" policy to allow credentials from localhost:3000 + // In development without Docker, use "Development" policy + app.UseCors(app.Environment.IsDevelopment() ? "Development" : "Docker"); // Serve static files (audio, etc.) app.UseStaticFiles(); @@ -323,8 +337,10 @@ try // Helper method to validate AI service configurations static void ValidateAiConfigurations(IConfiguration configuration) { - // Skip validation during EF migrations - if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true") + // Skip validation during EF migrations and Docker startup + // (In Docker, AI service configs may not be fully set) + if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true" || + Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true") { return; }