gpt4 book ai didi

.net - 解决混合内容错误的Swagger设置

转载 作者:行者123 更新时间:2023-12-05 06:51:24 25 4
gpt4 key购买 nike

我有一个由 swagger 记录的 dotnet 核心 web api。这是我的设置方式:

    public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddHealthChecks();
services.AddSingleton(sp =>
{
var options = new JsonSerializerOptions();
options.Converters.Add(new DateTimeOffsetConverter());
options.Converters.Add(new LabelDataConverter());
return options;
});
services.AddCacheManager(Configuration);
services.AddKafkaConsumers(Configuration);

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "X.WebApi", Version = "v1" });
});

services.AddInfluxDb(options => Configuration.GetSection("InfluxDb").Bind(options));
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "X.WebApi v1"));

app.UseRouting();

app.UseAuthorization();

app.UseHealthChecks("/health");

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}

我可以在本地机器上通过 swagger ui 运行端点,但是当我将应用程序部署到服务器时,我收到了 TypeError: Failed to fetch 错误。这是我在浏览器控制台上看到的:

swagger-ui-bundle.js:2 Mixed Content: The page at 'https://x.y.consul.z.com/swagger/index.html' was loaded over HTTPS, but requested an insecure resource 'http://x.y.consul.z.com/v1/Path/1'. This request has been blocked; the content must be served over HTTPS.

我应该如何更新 swagger 设置才能在服务器上正常运行?

最佳答案

您可以将 HTTPS 作为方案添加到您的 swagger UI 中以解决此问题:https://swagger.io/docs/specification/2-0/api-host-and-base-path/

关于.net - 解决混合内容错误的Swagger设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66178107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com