- Document every endpoint's responses (Produces<T>/status codes/validation) so the generated OpenAPI/Scalar docs carry response schemas and status codes instead of empty responses - Cache recently-synced user ids (IMemoryCache, 15 min) in the JWT TokenValidated handler so user provisioning no longer hits the DB on every authenticated request - Add ProblemDetails + UseExceptionHandler for consistent RFC7807 errors - Add ToCreatedResult ErrorOr helper and use it in the create endpoints - Normalize the playlists route to lowercase (/playlists) Verified: booted the Api against RabbitMQ + Postgres in Docker and inspected /openapi/v1.json — operations now expose response schemas/status codes and the route is /playlists. Build: 0 warnings, 0 errors.
41 lines
895 B
C#
41 lines
895 B
C#
using Musify.Infrastructure.Observability;
|
|
using Scalar.AspNetCore;
|
|
using Musify.Api.Endpoints;
|
|
using Musify.Api.Extensions;
|
|
|
|
var builder = WebApplication.CreateBuilder();
|
|
|
|
const string devCorsPolicy = "dev-cors";
|
|
|
|
builder.Services
|
|
.AddApplicationServices(builder.Configuration)
|
|
.AddObservability(builder.Configuration);
|
|
|
|
builder.Services.AddProblemDetails();
|
|
|
|
if (builder.Environment.IsDevelopment())
|
|
{
|
|
builder.Services.AddCors(options => options.AddPolicy(devCorsPolicy, policy =>
|
|
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
|
|
}
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseExceptionHandler();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseCors(devCorsPolicy);
|
|
app.MapOpenApi();
|
|
app.MapScalarApiReference();
|
|
}
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app
|
|
.MapPlayListEndpoints()
|
|
.MapTrackEndpoints()
|
|
.MapUserEndpoints();
|
|
|
|
app.Run(); |