diff --git a/ShoppingAssistantApi.Api/ApiExtentions/CorsExtension.cs b/ShoppingAssistantApi.Api/ApiExtentions/CorsExtension.cs new file mode 100644 index 0000000..75bd645 --- /dev/null +++ b/ShoppingAssistantApi.Api/ApiExtentions/CorsExtension.cs @@ -0,0 +1,21 @@ +namespace ShoppingAssistantApi.Api.ApiExtentions; + +public static class CorsExtension +{ + public static IServiceCollection AddCorsAllowAny(this IServiceCollection services) + { + services.AddCors(options => + { + options.AddPolicy("allowAnyOrigin", + builder => + { + builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader(); + }); + }); + + return services; + } +} diff --git a/ShoppingAssistantApi.Api/Program.cs b/ShoppingAssistantApi.Api/Program.cs index 6d67dd6..1ba6841 100644 --- a/ShoppingAssistantApi.Api/Program.cs +++ b/ShoppingAssistantApi.Api/Program.cs @@ -17,6 +17,7 @@ builder.Services.AddServices(); builder.Services.AddHttpClient(builder.Configuration); builder.Services.AddGraphQl(); builder.Services.AddControllers(); +builder.Services.AddCorsAllowAny(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); @@ -30,6 +31,8 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } +app.UseCors("allowAnyOrigin"); + app.UseHttpsRedirection(); app.UseAuthentication();