From 73732af9d214589dd68a6f5b1d867d253762721c Mon Sep 17 00:00:00 2001 From: Swoyam Date: Sat, 11 Oct 2025 11:10:33 +0530 Subject: [PATCH] Configure Program.cs with necessary middleware and services and Update ProblemsController to handle problem retrieval and filtering --- src/Backend/Controllers/ProblemsController.cs | 6 +++--- src/Backend/Program.cs | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Backend/Controllers/ProblemsController.cs b/src/Backend/Controllers/ProblemsController.cs index caf93e1..666ec93 100644 --- a/src/Backend/Controllers/ProblemsController.cs +++ b/src/Backend/Controllers/ProblemsController.cs @@ -6,6 +6,7 @@ namespace Backend.Controllers using ProblemPublicModel = Common.Models.Problem; [ApiController] + [Route("api/[controller]")] public class ProblemsController : ControllerBase { private AppContext appContext; @@ -19,15 +20,14 @@ public ProblemsController(AppContext appContext, ILogger log } [HttpGet] - [Route("")] + [Route("~/api/home")] public ActionResult GetHome() { return Ok("Leetcode Wrapper Backend is running."); } [HttpGet] - [Route("problems")] - public async Task> GetProblems( + public async Task>> GetProblems( [FromQuery(Name = QueryParam.Skip)] int skip = 0, [FromQuery(Name = QueryParam.Limit)] int limit = 50, [FromQuery(Name = QueryParam.Company)] List? companies = null, diff --git a/src/Backend/Program.cs b/src/Backend/Program.cs index 082f7f1..7583545 100644 --- a/src/Backend/Program.cs +++ b/src/Backend/Program.cs @@ -38,6 +38,16 @@ public static void Main(string[] args) builder.Services.AddApplicationInsightsTelemetry(); builder.Services.AddControllers(); + // Add CORS + builder.Services.AddCors(options => + { + options.AddPolicy("AllowReactApp", + builder => builder + .WithOrigins("http://localhost:3000") + .AllowAnyMethod() + .AllowAnyHeader()); + }); + SetupLogging(builder.Logging, builder.Configuration); if (builder.Environment.IsDevelopment()) @@ -72,7 +82,11 @@ public static void Main(string[] args) app.UseSwaggerUI(); } - app.UseHttpsRedirection(); + // Commenting out HTTPS redirection to allow HTTP + // app.UseHttpsRedirection(); + + // Use CORS before other middleware + app.UseCors("AllowReactApp"); app.UseAuthorization();