You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

34 lines
1004 B

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);
}
}