db8ed2a868
Add Swashbuckle.AspNetCore (v6.6.2) to API project and register Swagger services (AddEndpointsApiExplorer, AddSwaggerGen). Enable UseSwagger/UseSwaggerUI only in Development to expose /swagger for API exploration without affecting production behavior. Update codexInfo.md to document the dev-only Swagger endpoint.
40 lines
978 B
C#
40 lines
978 B
C#
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
var webRootPath = app.Environment.WebRootPath ?? Path.Combine(app.Environment.ContentRootPath, "wwwroot");
|
|
var indexFilePath = Path.Combine(webRootPath, "index.html");
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseDefaultFiles();
|
|
app.UseStaticFiles();
|
|
|
|
app.MapControllers();
|
|
app.MapFallback(async context =>
|
|
{
|
|
if (context.Request.Path.StartsWithSegments("/api"))
|
|
{
|
|
context.Response.StatusCode = StatusCodes.Status404NotFound;
|
|
return;
|
|
}
|
|
|
|
if (!File.Exists(indexFilePath))
|
|
{
|
|
context.Response.StatusCode = StatusCodes.Status404NotFound;
|
|
return;
|
|
}
|
|
|
|
context.Response.ContentType = "text/html; charset=utf-8";
|
|
await context.Response.SendFileAsync(indexFilePath);
|
|
});
|
|
|
|
app.Run();
|