Files
KonSoft.Clean/gateways/KonSoft.InternalGateway/InternalGatewayModule.cs

85 lines
2.8 KiB
C#

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
{
[DependsOn(
typeof(KonSoftSharedHostingGatewaysModule),
typeof(AdminHttpApiModule)
)]
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();
});
}
}
}