2025-06-15 11:29:46 +02:00
|
|
|
|
using Asp.Versioning.ApiExplorer;
|
|
|
|
|
|
using Vegasco.Server.Api.Endpoints;
|
2025-06-12 18:22:37 +02:00
|
|
|
|
using Vegasco.Server.ServiceDefaults;
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
2025-06-12 18:22:37 +02:00
|
|
|
|
namespace Vegasco.Server.Api.Common;
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
|
|
|
|
|
internal static class StartupExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static WebApplication ConfigureServices(this WebApplicationBuilder builder)
|
|
|
|
|
|
{
|
2024-12-28 17:01:18 +01:00
|
|
|
|
builder.AddServiceDefaults();
|
|
|
|
|
|
|
2024-08-17 16:38:40 +02:00
|
|
|
|
builder.Configuration.AddEnvironmentVariables("Vegasco_");
|
|
|
|
|
|
|
2025-06-12 18:22:37 +02:00
|
|
|
|
builder.AddApiServices();
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
|
|
|
|
|
WebApplication app = builder.Build();
|
|
|
|
|
|
return app;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal static WebApplication ConfigureRequestPipeline(this WebApplication app)
|
|
|
|
|
|
{
|
|
|
|
|
|
app.UseRequestLocalization(o =>
|
|
|
|
|
|
{
|
2025-06-13 19:39:37 +02:00
|
|
|
|
o.ApplyCurrentCultureToResponseHeaders = true;
|
2024-08-17 16:38:40 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
|
|
|
|
app.MapHealthChecks("/health");
|
|
|
|
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
|
|
app.MapEndpoints();
|
|
|
|
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
|
{
|
2025-06-12 17:58:50 +02:00
|
|
|
|
app.MapOpenApi("/swagger/{documentName}/swagger.json");
|
2025-06-15 11:29:46 +02:00
|
|
|
|
app.UseSwaggerUI(o =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create a Swagger endpoint for each API version
|
|
|
|
|
|
IReadOnlyList<ApiVersionDescription> apiVersions = app.DescribeApiVersions();
|
|
|
|
|
|
foreach (ApiVersionDescription apiVersionDescription in apiVersions)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = $"/swagger/{apiVersionDescription.GroupName}/swagger.json";
|
|
|
|
|
|
string name = apiVersionDescription.GroupName.ToUpperInvariant();
|
|
|
|
|
|
o.SwaggerEndpoint(url, name);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-08-17 16:38:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|