Skip to content

Commit 96ebc51

Browse files
author
Sergey Tregub
committed
Merge branch 'master' into rel-2.2
2 parents 0f620a6 + 606a406 commit 96ebc51

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

ProjectTemplates/ReferenceProject/Configuration/MiddlewareConfig.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.OpenApi.Models;
3+
using System.Collections.Generic;
24

35
namespace ReferenceProject
46
{
@@ -13,7 +15,22 @@ public static class MiddlewareConfig
1315
public static IApplicationBuilder UseSwaggerWithOptions(this IApplicationBuilder app)
1416
{
1517
// Enable middleware to serve generated Swagger as a JSON endpoint.
16-
SwaggerBuilderExtensions.UseSwagger(app);
18+
app.UseSwagger(c =>
19+
{
20+
c.PreSerializeFilters.Add((swaggerDoc, httpRequest) =>
21+
{
22+
if (!httpRequest.Headers.ContainsKey("X-Forwarded-Host")) return;
23+
24+
var serverUrl = $"{httpRequest.Headers["X-Forwarded-Proto"]}://" +
25+
$"{httpRequest.Headers["X-Forwarded-Host"]}" +
26+
$"{httpRequest.Headers["X-Forwarded-Prefix"]}";
27+
28+
swaggerDoc.Servers = new List<OpenApiServer>()
29+
{
30+
new OpenApiServer { Url = serverUrl }
31+
};
32+
});
33+
});
1734

1835
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
1936
// specifying the Swagger JSON endpoint.

ProjectTemplates/ReferenceProject/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class Constants
44
{
55
public static class Swagger
66
{
7-
public static string EndPoint => $"/swagger/{Version}/swagger.json";
7+
public static string EndPoint => $"../swagger/{Version}/swagger.json";
88
public static string ApiName => "My API";
99
public static string Version => "v1";
1010
}

0 commit comments

Comments
 (0)