mirror of
https://github.com/azaion/missions.git
synced 2026-06-21 06:31:08 +00:00
2840ccb9b6
ci/woodpecker/push/build-arm Pipeline was successful
This commit transitions the project from Azaion.Flights to Azaion.Missions, updating namespaces, DTOs, services, and database entities accordingly. The Docker configuration and entry points have been modified to reflect the new project structure. Additionally, the README and documentation have been updated to clarify the ongoing renaming process and its implications. All references to flights have been replaced with missions, ensuring consistency across the codebase.
91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using LinqToDB;
|
|
using LinqToDB.Data;
|
|
using Azaion.Missions.Auth;
|
|
using Azaion.Missions.Database;
|
|
using Azaion.Missions.Infrastructure;
|
|
using Azaion.Missions.Middleware;
|
|
using Azaion.Missions.Services;
|
|
|
|
const string DatabaseUrlEnvVar = "DATABASE_URL";
|
|
const string DatabaseUrlConfigKey = "Database:Url";
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var databaseUrl = ConfigurationResolver.ResolveRequiredOrThrow(
|
|
builder.Configuration,
|
|
DatabaseUrlEnvVar,
|
|
DatabaseUrlConfigKey,
|
|
"Database connection string");
|
|
|
|
var connectionString = databaseUrl.StartsWith("postgresql://")
|
|
? ConvertPostgresUrl(databaseUrl)
|
|
: databaseUrl;
|
|
|
|
builder.Services.AddScoped(_ =>
|
|
{
|
|
var options = new DataOptions().UsePostgreSQL(connectionString);
|
|
return new AppDataConnection(options);
|
|
});
|
|
|
|
builder.Services.AddScoped<MissionService>();
|
|
builder.Services.AddScoped<WaypointService>();
|
|
builder.Services.AddScoped<VehicleService>();
|
|
|
|
builder.Services.AddJwtAuth(builder.Configuration);
|
|
|
|
var allowedOrigins = builder.Configuration.GetSection("CorsConfig:AllowedOrigins").Get<string[]>() ?? Array.Empty<string>();
|
|
var allowAnyOrigin = builder.Configuration.GetValue<bool>("CorsConfig:AllowAnyOrigin");
|
|
CorsConfigurationValidator.EnsureSafeForEnvironment(allowedOrigins, allowAnyOrigin, builder.Environment.EnvironmentName);
|
|
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(policy =>
|
|
{
|
|
if (CorsConfigurationValidator.ShouldUsePermissivePolicy(allowedOrigins, allowAnyOrigin))
|
|
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
|
|
else
|
|
policy.WithOrigins(allowedOrigins).AllowAnyHeader().AllowAnyMethod();
|
|
});
|
|
});
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
|
|
if (CorsConfigurationValidator.ShouldWarnAboutPermissiveDefault(allowedOrigins, allowAnyOrigin))
|
|
{
|
|
app.Services
|
|
.GetRequiredService<ILogger<Program>>()
|
|
.LogWarning(CorsConfigurationValidator.PermissiveDefaultWarning, app.Environment.EnvironmentName);
|
|
}
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<AppDataConnection>();
|
|
DatabaseMigrator.Migrate(db);
|
|
}
|
|
|
|
app.UseMiddleware<ErrorHandlingMiddleware>();
|
|
app.UseCors();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
|
|
app.MapControllers();
|
|
app.MapGet("/health", () => Results.Ok(new { status = "healthy" }));
|
|
|
|
app.Run();
|
|
|
|
static string ConvertPostgresUrl(string url)
|
|
{
|
|
var uri = new Uri(url);
|
|
var userInfo = uri.UserInfo.Split(':');
|
|
var host = uri.Host;
|
|
var port = uri.Port > 0 ? uri.Port : 5432;
|
|
var database = uri.AbsolutePath.TrimStart('/');
|
|
return $"Host={host};Port={port};Database={database};Username={userInfo[0]};Password={userInfo.ElementAtOrDefault(1) ?? ""}";
|
|
}
|