From 997c06b69399bc1921d6560bb0d9ce932a102baf Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 19 Mar 2024 06:51:44 +0100 Subject: [PATCH] try --- src/HeartTrackAPI/Utils/AppBootstrap.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/HeartTrackAPI/Utils/AppBootstrap.cs b/src/HeartTrackAPI/Utils/AppBootstrap.cs index 8b54334..c41052e 100644 --- a/src/HeartTrackAPI/Utils/AppBootstrap.cs +++ b/src/HeartTrackAPI/Utils/AppBootstrap.cs @@ -172,6 +172,7 @@ public class AppBootstrap(IConfiguration configuration) public void Configure(WebApplication app, IWebHostEnvironment env) { +// app.UsePathBase("/containers/HeartDev-api"); app.UseHttpsRedirection(); app.MapIdentityApi(); @@ -184,8 +185,28 @@ public class AppBootstrap(IConfiguration configuration) if (true) { var apiVersionDescriptionProvider = app.Services.GetRequiredService(); - app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwagger(options => + { + options.PreSerializeFilters.Add((swagger, httpReq) => + { + if (httpReq.Headers.ContainsKey("X-Forwarded-Host")) + { + //The httpReq.PathBase and httpReq.Headers["X-Forwarded-Prefix"] is what we need to get the base path. + //For some reason, they returning as null/blank. Perhaps this has something to do with how the proxy is configured which we don't have control. + //For the time being, the base path is manually set here that corresponds to the APIM API Url Prefix. + //In this case we set it to 'sample-app'. + + var basePath = "/containers/HeartDev-api"; + var serverUrl = $"{httpReq.Scheme}://{httpReq.Headers["X-Forwarded-Host"]}/{basePath}"; + swagger.Servers = new List { new OpenApiServer { Url = serverUrl } }; + } + }); + }); + app.UseSwaggerUI(options => + { + options.RoutePrefix = string.Empty; + options.SwaggerEndpoint("swagger/v1/swagger.json", "My Api (v1)"); + }); app.MapSwagger(); /* app.UseSwaggerUI(options => {