From 025983bd21d6a0409d70527bb3c619f5ec5312e5 Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Thu, 7 Dec 2023 01:08:37 +0000 Subject: [PATCH] Update CORS to make it run on localhost --- backend/README.md | 1 + backend/YPS.Beer/Program.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/README.md b/backend/README.md index 9967549..b1255fd 100644 --- a/backend/README.md +++ b/backend/README.md @@ -16,6 +16,7 @@ To run in development mode, you will need: ### Running locally To run in development mode, run: ```sh +cd YPS.Beer/ dotnet run ``` diff --git a/backend/YPS.Beer/Program.cs b/backend/YPS.Beer/Program.cs index 774f981..e94f5fc 100644 --- a/backend/YPS.Beer/Program.cs +++ b/backend/YPS.Beer/Program.cs @@ -29,7 +29,10 @@ builder.Services.AddAuthentication(IdentityConstants.ApplicationScheme) .AddApplicationCookie(); builder.Services.AddAuthorizationBuilder(); -builder.Services.AddCors(); +builder.Services.AddCors(options => +{ + options.AddDefaultPolicy(policy => policy.WithOrigins("http://localhost:3000").AllowAnyMethod().AllowAnyHeader().AllowCredentials()); +}); var app = builder.Build(); @@ -37,12 +40,16 @@ if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); - - app.UseCors(cors => cors.AllowAnyHeader().AllowAnyMethod().SetIsOriginAllowed(_ => true).AllowCredentials()); } +app.UseRouting(); + app.UseHttpsRedirection(); +app.UseCors(); + +app.UseAuthorization(); + app.MapControllers(); app.MapIdentityApi();