I am currently developing a web api using f#, I am totally new to it as I am coming from a c# background, and I would like to fetch datas from a reactjs application. But I need to allow cors on my f# webapi. I am totally lost when I am trying to allow cors. So far, I added :
member this.ConfigureServices(services: IServiceCollection) =
services.AddCors() |> ignore
and I have tried to add
app.UseCors() |> ignore
to the configure member, but I don't understand how to implement this method to allow cors in my application. I have also tried to add
[<EnableCors("...")>]
on my controller but I don't know what to put inside it
Any help would be very appreciate
Edit 1: So far here is what I have :
module ConfigurationCors =
let ConfigureCors(corsBuilder: CorsPolicyBuilder): unit =
corsBuilder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials() |> ignore
open ConfigurationCors
type Startup private () =
new (configuration: IConfiguration) as this =
Startup() then
this.Configuration <- configuration
// This method gets called by the runtime. Use this method to add services to the container.
member this.ConfigureServices(services: IServiceCollection) =
// Add framework services.
services.AddCors() |> ignore
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) |> ignore
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) =
if (env.IsDevelopment()) then
app.UseDeveloperExceptionPage() |> ignore
else
app.UseHsts() |> ignore
app.UseHttpsRedirection() |> ignore
app.UseMvc() |> ignore
app.UseCors(Action<CorsPolicyBuilder> ConfigureCors) |> ignore
member val Configuration : IConfiguration = null with get, set
I have instanciate a module and a function inside it that I am passing to UseCors but it seems it's not working, is it the good way ? If someone has a hint and could help me.
Here is my fetch method in my react app :
fetch('https://localhost:44323/api/values')
.then(response => response.json())
.then(data => {
console.log(data)
})