From 8cf7982c1f10000fad2bb79b3c840f68778e25e6 Mon Sep 17 00:00:00 2001 From: PA4KEV Date: Mon, 26 Jun 2023 21:38:07 +0200 Subject: [PATCH] Add CORS configurations --- api/Program.fs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/Program.fs b/api/Program.fs index 5c8aa62..2f6ff62 100644 --- a/api/Program.fs +++ b/api/Program.fs @@ -1,4 +1,5 @@ open Microsoft.AspNetCore.Builder +open Microsoft.AspNetCore.Cors.Infrastructure open Microsoft.AspNetCore.Hosting open Microsoft.Extensions.Hosting open Microsoft.Extensions.DependencyInjection @@ -32,14 +33,28 @@ let endpointsList = [ (* Infrastructure Configuration *) +let configureCors (builder : CorsPolicyBuilder) = + builder + .WithOrigins( + "http://localhost:5218", + "https://localhost:5218", + "http://localhost:3000", + "https://localhost:3000") + .AllowAnyMethod() + .AllowAnyHeader() + |> ignore + let configureApp (app : IApplicationBuilder) = app .UseRouting() + .UseCors(configureCors) .UseEndpoints(fun e -> e.MapGiraffeEndpoints(endpointsList)) |> ignore + let configureServices (services : IServiceCollection) = // Add Giraffe dependencies + services.AddCors() |> ignore services.AddGiraffe() |> ignore []