Files
raceplanner/backend/Program.cs
T
2026-04-03 20:55:58 +02:00

47 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using RacePlannerApi.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi();
// Configure Entity Framework Core with PostgreSQL
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
?? "Host=localhost;Database=RacePlanner;Username=postgres;Password=postgres";
builder.Services.AddDbContext<RacePlannerDbContext>(options =>
options.UseNpgsql(connectionString));
// Add CORS for frontend
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowFrontend", policy =>
{
policy.WithOrigins("http://localhost:3000")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
// Apply CORS
app.UseCors("AllowFrontend");
app.UseAuthorization();
app.MapControllers();
app.Run();