Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Backend/Controllers/ProblemsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Backend.Controllers
using ProblemPublicModel = Common.Models.Problem;

[ApiController]
[Route("api/[controller]")]
public class ProblemsController : ControllerBase
{
private AppContext appContext;
Expand All @@ -19,15 +20,14 @@ public ProblemsController(AppContext appContext, ILogger<ProblemsController> log
}

[HttpGet]
[Route("")]
[Route("~/api/home")]
public ActionResult<string> GetHome()
{
return Ok("Leetcode Wrapper Backend is running.");
}

[HttpGet]
[Route("problems")]
public async Task<ActionResult<ProblemPublicModel>> GetProblems(
public async Task<ActionResult<IEnumerable<ProblemPublicModel>>> GetProblems(
[FromQuery(Name = QueryParam.Skip)] int skip = 0,
[FromQuery(Name = QueryParam.Limit)] int limit = 50,
[FromQuery(Name = QueryParam.Company)] List<string>? companies = null,
Expand Down
16 changes: 15 additions & 1 deletion src/Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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();

Expand Down