LANCommander/LANCommander.Server/Extensions/EndpointExtensions.cs
Aaron Powell 8e5a4f6bf4 Refactoring startup for easier understanding and tracing
Broke the startup of the app into a series of extension methods (and classes to contain them), rather than one long method. This means the stack tracers are easier to follow when the startup fails, and it's clearer what's happening when throughout the pipeline.

I've included a few optimisations, such as starting to rely more on DI for injecting things (like the logger) rather than the static logger, which in turn can help with testability and evaluation of the callstack.
2025-01-02 11:40:15 +11:00

30 lines
882 B
C#

using LANCommander.Server.Services;
namespace LANCommander.Server;
public static class EndpointExtensions
{
public static void UseRobots(this WebApplication app) =>
app.Use(async (context, next) =>
{
if (context.Request.Path.StartsWithSegments("/robots.txt"))
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("User-agent: *\nDisallow: /Identity/");
return;
}
await next();
});
public static void UseApiVersioning(this WebApplication app) =>
app.Use((context, next) =>
{
var headers = context.Response.Headers;
headers.Append("X-API-Version", UpdateService.GetCurrentVersion().ToString());
return next();
});
}