feat 网关继承微服务Swagger
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
using KonSoft.Admin;
|
||||
using KonSoft.Shared.Hosting.AspNetCore;
|
||||
using KonSoft.Shared.Hosting.Gateways;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Rewrite;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.InternalGateway
|
||||
@ -10,5 +14,71 @@ namespace KonSoft.InternalGateway
|
||||
)]
|
||||
public class InternalGatewayModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
||||
|
||||
SwaggerConfigurationHelper.ConfigureWithOidc(
|
||||
context: context,
|
||||
authority: configuration["AuthServer:Authority"]!,
|
||||
scopes:
|
||||
[
|
||||
"Admin", "Dispatch", "Payment", "Report", "TenantManagement"
|
||||
],
|
||||
apiTitle: "Internal Gateway API",
|
||||
discoveryEndpoint: configuration["AuthServer:MetadataAddress"]
|
||||
);
|
||||
|
||||
context.Services.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(builder =>
|
||||
{
|
||||
builder
|
||||
.WithOrigins(
|
||||
configuration["App:CorsOrigins"]!
|
||||
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(o => o.Trim().RemovePostFix("/"))
|
||||
.ToArray()
|
||||
)
|
||||
.WithAbpExposedHeaders()
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
context.Services.AddMemoryCache();
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
var app = context.GetApplicationBuilder();
|
||||
var env = context.GetEnvironment();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseCorrelationId();
|
||||
app.UseCors();
|
||||
app.UseAbpRequestLocalization();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
app.UseSwaggerUIWithYarp(context);
|
||||
app.UseAbpSerilogEnrichers();
|
||||
|
||||
app.UseRewriter(new RewriteOptions()
|
||||
// Regex for "", "/" and "" (whitespace)
|
||||
.AddRedirect("^(|\\|\\s+)$", "/swagger"));
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapReverseProxyWithLocalization();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user