application.configuration ve allowedHosts kısmına Wildcard seçeneği eklendi

This commit is contained in:
Sedat ÖZTÜRK 2025-08-12 17:19:38 +03:00
parent 9a8e6145ec
commit 821806a8db
5 changed files with 11 additions and 22 deletions

View file

@ -78,7 +78,6 @@ public class Program
var extraOrigins = (builder.Configuration["App:CorsOrigins"] ?? "") var extraOrigins = (builder.Configuration["App:CorsOrigins"] ?? "")
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
// Her ortamda tek policy tanımla; kuralları içeride ayır
builder.Services.AddCors(options => builder.Services.AddCors(options =>
{ {
options.AddPolicy("Dynamic", policy => options.AddPolicy("Dynamic", policy =>
@ -95,9 +94,8 @@ public class Program
var scheme = uri.Scheme.ToLowerInvariant(); var scheme = uri.Scheme.ToLowerInvariant();
var host = uri.Host.ToLowerInvariant(); var host = uri.Host.ToLowerInvariant();
if (builder.Environment.IsProduction()) if (builder.Environment.IsProduction()) //IsProduction
{ {
// PROD: sadece HTTPS + *.baseDomain + (isteğe bağlı) extraOrigins
if (scheme != "https") return false; if (scheme != "https") return false;
if (!string.IsNullOrWhiteSpace(baseDomain)) if (!string.IsNullOrWhiteSpace(baseDomain))
@ -107,7 +105,6 @@ public class Program
return true; return true;
} }
// App:CorsOrigins içindeki tam domainleri de kabul et
foreach (var o in extraOrigins) foreach (var o in extraOrigins)
{ {
if (Uri.TryCreate(o, UriKind.Absolute, out var eo) if (Uri.TryCreate(o, UriKind.Absolute, out var eo)
@ -120,22 +117,13 @@ public class Program
return false; return false;
} }
else else //IsDevelopment
{ {
// DEV/LOCAL: localhost ve dev-* subdomainleri if (scheme == "https" && (host == "localhost" || host == "127.0.0.1" || host == "[::1]")
if (host == "localhost" || host == "127.0.0.1" || host == "[::1]") || (scheme == "http" && (host == "localhost" || host == "127.0.0.1" || host == "[::1]"))
|| (!string.IsNullOrWhiteSpace(baseDomain) && (host == $"dev.{baseDomain.ToLowerInvariant()}")))
return true; return true;
// Örn. dev-*.sozsoft.com gibi bir pattern istiyorsan:
if (!string.IsNullOrWhiteSpace(baseDomain) &&
(host.StartsWith("dev-") && host.EndsWith("." + baseDomain!.ToLowerInvariant())))
return true;
// İstersen http de kabul et (vite genelde http çalışır)
if (scheme == "http" && (host == "localhost" || host == "127.0.0.1"))
return true;
// İsteğe bağlı: extraOrigins developmentta da geçerli olsun dersen:
foreach (var o in extraOrigins) foreach (var o in extraOrigins)
{ {
if (Uri.TryCreate(o, UriKind.Absolute, out var eo) if (Uri.TryCreate(o, UriKind.Absolute, out var eo)

View file

@ -6,7 +6,8 @@
"RedirectAllowedUrls": "https://dev.sozsoft.com,https://dev.sozsoft.com/authentication/callback", "RedirectAllowedUrls": "https://dev.sozsoft.com,https://dev.sozsoft.com/authentication/callback",
"AttachmentsPath": "/etc/api/mail-queue/attachments", "AttachmentsPath": "/etc/api/mail-queue/attachments",
"CdnPath": "/etc/api/cdn", "CdnPath": "/etc/api/cdn",
"ImportPath": "/etc/api/import" "ImportPath": "/etc/api/import",
"BaseDomain": "sozsoft.com"
}, },
"ConnectionStrings": { "ConnectionStrings": {
"SqlServer": "Server=sql;Database=KURS;User Id=sa;password=NvQp8s@l;Trusted_Connection=False;TrustServerCertificate=True;", "SqlServer": "Server=sql;Database=KURS;User Id=sa;password=NvQp8s@l;Trusted_Connection=False;TrustServerCertificate=True;",

View file

@ -2,12 +2,12 @@
"App": { "App": {
"SelfUrl": "https://api.sozsoft.com", "SelfUrl": "https://api.sozsoft.com",
"ClientUrl": "https://sozsoft.com", "ClientUrl": "https://sozsoft.com",
"BaseDomain": "sozsoft.com",
"CorsOrigins": "https://sozsoft.com", "CorsOrigins": "https://sozsoft.com",
"RedirectAllowedUrls": "https://sozsoft.com,https://sozsoft.com/authentication/callback", "RedirectAllowedUrls": "https://sozsoft.com,https://sozsoft.com/authentication/callback",
"AttachmentsPath": "/etc/api/mail-queue/attachments", "AttachmentsPath": "/etc/api/mail-queue/attachments",
"CdnPath": "/etc/api/cdn", "CdnPath": "/etc/api/cdn",
"ImportPath": "/etc/api/import" "ImportPath": "/etc/api/import",
"BaseDomain": "sozsoft.com"
}, },
"ConnectionStrings": { "ConnectionStrings": {
"SqlServer": "Server=sql;Database=KURS;User Id=sa;password=NvQp8s@l;Trusted_Connection=False;TrustServerCertificate=True;", "SqlServer": "Server=sql;Database=KURS;User Id=sa;password=NvQp8s@l;Trusted_Connection=False;TrustServerCertificate=True;",

View file

@ -2,7 +2,7 @@
"App": { "App": {
"SelfUrl": "https://localhost:44344", "SelfUrl": "https://localhost:44344",
"ClientUrl": "http://localhost:3000", "ClientUrl": "http://localhost:3000",
"CorsOrigins": "http://localhost,http://localhost:3000,http://localhost:3001,http://localhost:3003,http://localhost:4200,http://localhost:5173", "CorsOrigins": "http://localhost,http://localhost:3000,http://localhost:4200",
"RedirectAllowedUrls": "http://localhost:4200,http://localhost:4200/authentication/callback", "RedirectAllowedUrls": "http://localhost:4200,http://localhost:4200/authentication/callback",
"AttachmentsPath": "C:\\Private\\Projects\\sozsoft\\configs\\mail-queue\\attachments", "AttachmentsPath": "C:\\Private\\Projects\\sozsoft\\configs\\mail-queue\\attachments",
"CdnPath": "C:\\Private\\Projects\\sozsoft\\configs\\docker\\data\\cdn", "CdnPath": "C:\\Private\\Projects\\sozsoft\\configs\\docker\\data\\cdn",

View file

@ -65,7 +65,7 @@ export default defineConfig(async ({ mode }) => {
host: '0.0.0.0', host: '0.0.0.0',
port: 80, port: 80,
open: false, open: false,
allowedHosts, allowedHosts: ['localhost', '.sozsoft.com'],
}, },
define: { define: {
'process.env': {}, 'process.env': {},