Files
astrain/src/ASTRAIN.Api/Program.cs
troogs fd8395cc48 Update configuration for deployment
- Change API base address to external IP for development
- Update launch settings to bind to any host interface
- Remove commented CORS policy code
2026-02-04 21:29:00 +01:00

67 lines
1.5 KiB
C#

using ASTRAIN.Api.Data;
using ASTRAIN.Api.Endpoints;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.FileProviders;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddDbContext<AppDbContext>(options =>
{
var connectionString = builder.Configuration.GetConnectionString("Default")
?? "Data Source=Data/astrain.db";
options.UseSqlite(connectionString);
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/openapi/v1.json", "ASTRAIN API");
options.RoutePrefix = "docs";
});
}
// app.UseHttpsRedirection();
app.UseCors();
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true
});
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
db.Database.EnsureCreated();
}
var api = app.MapGroup("/api");
api.MapHealthEndpoints();
api.MapUserEndpoints();
api.MapExerciseEndpoints();
api.MapRoutineEndpoints();
api.MapRoutineRunEndpoints();
app.MapFallbackToFile("index.html");
app.Run();