upd: 网关添加swagger
This commit is contained in:
@ -2,6 +2,7 @@ using KonSoft.InternalGateway;
|
|||||||
using KonSoft.InternalGateway.Extensions;
|
using KonSoft.InternalGateway.Extensions;
|
||||||
using KonSoft.Shared.Hosting.AspNetCore;
|
using KonSoft.Shared.Hosting.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Rewrite;
|
using Microsoft.AspNetCore.Rewrite;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
var assemblyName = typeof(Program).Assembly.GetName().Name!;
|
var assemblyName = typeof(Program).Assembly.GetName().Name!;
|
||||||
@ -19,16 +20,28 @@ try
|
|||||||
.AddAppSettingsSecretsJson()
|
.AddAppSettingsSecretsJson()
|
||||||
.UseAutofac()
|
.UseAutofac()
|
||||||
.UseSerilog();
|
.UseSerilog();
|
||||||
|
|
||||||
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerDoc("v1", new OpenApiInfo
|
||||||
|
{
|
||||||
|
Title = "Gateway",
|
||||||
|
Version = "v1"
|
||||||
|
});
|
||||||
|
options.DocInclusionPredicate((docName, description) => true);
|
||||||
|
options.CustomSchemaIds(type => type.FullName);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddReverseProxy()
|
builder.Services.AddReverseProxy()
|
||||||
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
|
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
await builder.AddApplicationAsync<InternalGatewayModule>();
|
await builder.AddApplicationAsync<InternalGatewayModule>();
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
await app.InitializeApplicationAsync();
|
await app.InitializeApplicationAsync();
|
||||||
|
app.UseSwaggerUIWithYarp();
|
||||||
app.MapReverseProxy();
|
app.MapReverseProxy();
|
||||||
app.MapGet("/heath", () => "Online");
|
app.MapGet("/heath", () => "Online");
|
||||||
app.UseSwaggerUIWithYarp();
|
|
||||||
app.UseRewriter(new RewriteOptions().AddRedirect("^(|\\|\\s+)$", "/swagger"));
|
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user