Applied CORS fix

This commit is contained in:
2026-10-24 14:58:55 +02:00
parent c43e18f184
commit 1233f15b91
2 changed files with 26 additions and 1 deletions
+25 -1
View File
@@ -116,7 +116,30 @@ builder.Services.AddCors(options =>
{
options.AddPolicy(CorsPolicy, policy =>
{
policy.WithOrigins(allowedOrigins)
policy.SetIsOriginAllowed(origin =>
{
if (string.IsNullOrWhiteSpace(origin)) return false;
var clean = origin.TrimEnd('/');
if (allowedOrigins.Any(a => string.Equals(a.TrimEnd('/'), clean, StringComparison.OrdinalIgnoreCase)))
return true;
try
{
var host = new Uri(origin).Host;
if (host.EndsWith("khongisa.co.za", StringComparison.OrdinalIgnoreCase) ||
host.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
host.Equals("127.0.0.1", StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
catch
{
// ignore parse failure
}
return false;
})
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
@@ -131,6 +154,7 @@ var scheduler = await schedulerFactory.GetScheduler();
if (scheduler!.Status != SchedulerStatus.Running)
await scheduler.Start();
app.UseCors(CorsPolicy);
app.UseHsts();
app.UseHttpsRedirection();
app.UseRouting();
+1
View File
@@ -22,6 +22,7 @@ services:
- CorsOrigins__0=${CORS_ORIGIN_CONSOLE:-https://console.ifri.khongisa.co.za}
- CorsOrigins__1=${CORS_ORIGIN_API:-https://api.ifri.khongisa.co.za}
- CorsOrigins__2=${CORS_ORIGIN_LOCAL:-https://localhost:7208}
- CorsOrigins__3=${CORS_ORIGIN_PARTNER:-https://partner.ifri.khongisa.co.za}
# Postgres Database Overrides
- ConnectionStrings__PfmDatabase=Server=${POSTGRES_HOST:-192.168.1.170};Port=${POSTGRES_PORT:-5432};Database=${POSTGRES_DB:-pfm};User Id=${POSTGRES_USER:-pfm-user};Password=${POSTGRES_PASSWORD:-};