Applied CORS fix #166
@@ -116,7 +116,30 @@ builder.Services.AddCors(options =>
|
|||||||
{
|
{
|
||||||
options.AddPolicy(CorsPolicy, policy =>
|
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()
|
.AllowAnyHeader()
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowCredentials();
|
.AllowCredentials();
|
||||||
@@ -131,6 +154,7 @@ var scheduler = await schedulerFactory.GetScheduler();
|
|||||||
if (scheduler!.Status != SchedulerStatus.Running)
|
if (scheduler!.Status != SchedulerStatus.Running)
|
||||||
await scheduler.Start();
|
await scheduler.Start();
|
||||||
|
|
||||||
|
app.UseCors(CorsPolicy);
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ services:
|
|||||||
- CorsOrigins__0=${CORS_ORIGIN_CONSOLE:-https://console.ifri.khongisa.co.za}
|
- CorsOrigins__0=${CORS_ORIGIN_CONSOLE:-https://console.ifri.khongisa.co.za}
|
||||||
- CorsOrigins__1=${CORS_ORIGIN_API:-https://api.ifri.khongisa.co.za}
|
- CorsOrigins__1=${CORS_ORIGIN_API:-https://api.ifri.khongisa.co.za}
|
||||||
- CorsOrigins__2=${CORS_ORIGIN_LOCAL:-https://localhost:7208}
|
- CorsOrigins__2=${CORS_ORIGIN_LOCAL:-https://localhost:7208}
|
||||||
|
- CorsOrigins__3=${CORS_ORIGIN_PARTNER:-https://partner.ifri.khongisa.co.za}
|
||||||
|
|
||||||
# Postgres Database Overrides
|
# 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:-};
|
- 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:-};
|
||||||
|
|||||||
Reference in New Issue
Block a user