From 03d9fa054f02bcc9e547449da3a932037155fc98 Mon Sep 17 00:00:00 2001 From: XShine555 Date: Sun, 31 May 2026 19:25:15 +0200 Subject: [PATCH] Allow any CORS origin in Development --- StreamingGateway/Program.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/StreamingGateway/Program.cs b/StreamingGateway/Program.cs index 4e03270..101bfb4 100644 --- a/StreamingGateway/Program.cs +++ b/StreamingGateway/Program.cs @@ -14,11 +14,17 @@ builder.Services.AddSingleton(); const string corsPolicy = "media-clients"; var allowedOrigins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get() ?? []; -builder.Services.AddCors(options => options.AddPolicy(corsPolicy, policy => policy - .WithOrigins(allowedOrigins) - .AllowAnyHeader() - .WithMethods("GET", "HEAD") - .WithExposedHeaders("Content-Range", "Accept-Ranges", "Content-Length"))); +builder.Services.AddCors(options => options.AddPolicy(corsPolicy, policy => +{ + if (builder.Environment.IsDevelopment()) + policy.AllowAnyOrigin(); + else + policy.WithOrigins(allowedOrigins); + + policy.AllowAnyHeader() + .WithMethods("GET", "HEAD") + .WithExposedHeaders("Content-Range", "Accept-Ranges", "Content-Length"); +})); builder.Services .AddReverseProxy()