using Microsoft.AspNetCore.Http; namespace DealerSelection.Common.Middleware; public class SwaggerRootRoutingMiddleware { public const string SwaggerUrl = "help/ui"; private readonly RequestDelegate _requestDelegate; private string PathBase { get; } public SwaggerRootRoutingMiddleware(RequestDelegate requestDelegate) { _requestDelegate = requestDelegate; PathBase = "/Booking/1.0"; } public async Task Invoke(HttpContext context) { if(context.Request.Method == "GET" && context.Request.Path.Value!.Contains("/index.html", StringComparison.OrdinalIgnoreCase) && !context.Request.Path.Value.Contains($"{SwaggerUrl}/index.html", StringComparison.OrdinalIgnoreCase)) { #if DEBUG context.Response.Redirect($"{SwaggerUrl}/index.html"); #else context.Response.Redirect($"{PathBase}/{SwaggerUrl}/index.html"); #endif return; } await _requestDelegate(context); } }