Applied configurable CORS policy to API

This commit is contained in:
2026-09-15 07:29:58 +02:00
parent f4a1064003
commit b239c402fa
3 changed files with 24 additions and 2 deletions
+15 -2
View File
@@ -91,6 +91,19 @@ builder.Services.AddOpenApi(options =>
});
});
var allowedOrigins = builder.Configuration.GetSection("CorsOrigins").Get<string[]>() ?? [];
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowConfiguredOrigins", policy =>
{
policy.WithOrigins(allowedOrigins)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
var app = builder.Build();
var schedulerFactory = app.Services.GetRequiredService<ISchedulerFactory>();
@@ -101,10 +114,10 @@ if (!scheduler!.IsStarted)
app.UseHsts();
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("AllowConfiguredOrigins");
app.UseOutputCache();
app.UseAuthentication();
app.UseAuthorization();