From 7be84755b03527147d255b6ddf27c065ebc782c8 Mon Sep 17 00:00:00 2001 From: H Vs Date: Thu, 16 May 2024 16:35:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TelpoKafkaConsole.WebApi/Program.cs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/TelpoKafkaConsole.WebApi/Program.cs b/TelpoKafkaConsole.WebApi/Program.cs index 8ff4b0c..e545660 100644 --- a/TelpoKafkaConsole.WebApi/Program.cs +++ b/TelpoKafkaConsole.WebApi/Program.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Configuration; +using Microsoft.OpenApi.Models; using Serilog; using TelpoKafkaConsole.Model; using TelpoKafkaConsole.Service; @@ -47,15 +48,28 @@ namespace TelpoKafkaConsole.WebApi var app = builder.Build(); // Configure the HTTP request pipeline. - //if (app.Environment.IsDevelopment()) - //{ - // app.UseSwagger(); - // app.UseSwaggerUI(); - //} + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + + } + else + { + var prefix = "kafkaconsole"; + app.UseSwagger(c => + { + c.PreSerializeFilters.Add((swagger, httpReq) => + { + var scheme = httpReq.Headers.TryGetValue("X-Forwarded-Proto", out var v2) ? v2.ToString() : httpReq.Scheme; + swagger.Servers = new List { new OpenApiServer { Url = $"{scheme}://{httpReq.Host}/{prefix}" } }; + }); + }); + } - app.UseSwagger(); app.UseSwaggerUI(); + + app.UseAuthorization(); app.UseMiddleware();