From 8f75a86373c4cd9860d6cf708482f0b79b391224 Mon Sep 17 00:00:00 2001 From: swapnamol-abraham Date: Mon, 1 Dec 2025 12:51:37 +0000 Subject: [PATCH] TD-6384: CORS Policy Changes for Moodle Heart beat --- LearningHub.Nhs.WebUI/Program.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/LearningHub.Nhs.WebUI/Program.cs b/LearningHub.Nhs.WebUI/Program.cs index c24d9057c..8f4852c2c 100644 --- a/LearningHub.Nhs.WebUI/Program.cs +++ b/LearningHub.Nhs.WebUI/Program.cs @@ -35,6 +35,19 @@ builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); builder.Host.UseNLog(); + string corsMoodleUrl = builder.Configuration.GetValue("MoodleAPIConfig:BaseUrl"); + + builder.Services.AddCors(options => + { + options.AddPolicy("MoodleCORS", builder => + { + builder.WithOrigins(corsMoodleUrl) + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); + }); + builder.Services.AddHostedService(); builder.Services.ConfigureServices(builder.Configuration, builder.Environment); @@ -78,6 +91,8 @@ app.UseHttpsRedirection(); } + app.UseCors("MoodleCORS"); + app.UseRouting(); app.UseAuthentication();