From 32c70ca1d65b4df00069b973e93356a7da1eac69 Mon Sep 17 00:00:00 2001 From: "Tizian.Breuch" Date: Fri, 26 Sep 2025 15:16:39 +0200 Subject: [PATCH] cors --- Webshop.Api/Program.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Webshop.Api/Program.cs b/Webshop.Api/Program.cs index c277e72..fbf72c8 100644 --- a/Webshop.Api/Program.cs +++ b/Webshop.Api/Program.cs @@ -35,15 +35,21 @@ var options = new WebApplicationOptions var builder = WebApplication.CreateBuilder(options); +var allowedOrigins = new string[] +{ + "https://webshop.tzbre.dev", + "http://localhost:4200" +}; + builder.Services.AddCors(options => { - options.AddPolicy("AllowNuxtApp", - policy => - { - policy.WithOrigins("http://localhost:3000") - .AllowAnyHeader() - .AllowAnyMethod(); - }); + options.AddPolicy(name: "AllowSpecificOrigins", + policy => + { + policy.WithOrigins(allowedOrigins) + .AllowAnyHeader() + .AllowAnyMethod(); + }); }); // --- 1. Dependency Injection Konfiguration --- @@ -300,8 +306,8 @@ app.UseStaticFiles(); // Swagger/SwaggerUI für API-Dokumentation aktivieren //'if (app.Environment.IsDevelopment()) //{ - app.UseSwagger(); - app.UseSwaggerUI(); +app.UseSwagger(); +app.UseSwaggerUI(); //} // app.UseHttpsRedirection(); // Auskommentiert für Docker HTTP-Entwicklung