56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
using Asp.Versioning.ApiExplorer;
|
|
using Vegasco.Server.Api.Endpoints;
|
|
using Vegasco.Server.ServiceDefaults;
|
|
|
|
namespace Vegasco.Server.Api.Common;
|
|
|
|
internal static class StartupExtensions
|
|
{
|
|
internal static WebApplication ConfigureServices(this WebApplicationBuilder builder)
|
|
{
|
|
builder.AddServiceDefaults();
|
|
|
|
builder.Configuration.AddEnvironmentVariables("Vegasco_");
|
|
|
|
builder.AddApiServices();
|
|
|
|
WebApplication app = builder.Build();
|
|
return app;
|
|
}
|
|
|
|
internal static WebApplication ConfigureRequestPipeline(this WebApplication app)
|
|
{
|
|
app.UseRequestLocalization(o =>
|
|
{
|
|
o.ApplyCurrentCultureToResponseHeaders = true;
|
|
});
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapHealthChecks("/health");
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapEndpoints();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi("/swagger/{documentName}/swagger.json");
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
return app;
|
|
}
|
|
}
|