Cleanup and more fixes

This commit is contained in:
Jonathan Bourdon
2024-06-20 16:27:44 -04:00
parent ba35e3228e
commit 81e9290989
10 changed files with 57 additions and 1025 deletions

View File

@@ -4,6 +4,8 @@ using Hutopy.Infrastructure.Data;
using Hutopy.Web;
using Azure.Identity;
using Microsoft.AspNetCore.HttpOverrides;
using NSwag;
using NSwag.Generation.Processors.Security;
var builder = WebApplication.CreateBuilder(args);
@@ -48,6 +50,25 @@ builder.Services.AddWebServices();
builder.Services.AddAuthorizationAndAuthentication(builder.Configuration);
builder.Services.AddControllers();
builder.Services.AddOpenApiDocument((configure, sp) =>
{
configure.Title = "Hutopy API";
// Add JWT
configure.AddSecurity(
"JWT",
[],
new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.ApiKey,
Name = "Authorization",
In = OpenApiSecurityApiKeyLocation.Header,
Description = "Type into the textbox: Bearer {your JWT token}."
});
configure.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
});
var app = builder.Build();
app.UseForwardedHeaders(
@@ -75,22 +96,18 @@ app.UseHealthChecks("/health");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSwaggerUi(settings =>
if (app.Environment.IsDevelopment())
{
settings.Path = "/api";
settings.DocumentPath = "/api/specification.json";
});
app.UseOpenApi();
app.UseSwaggerUi(options => options.Path = "/api");
}
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html");
app.UseExceptionHandler(options => { });
app.Map("/", () => Results.Redirect("/api"));
//TODO: validate the behavior
// app.UseExceptionHandler();
app.MapEndpoints();
app.Run();