You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.5 KiB
113 lines
3.5 KiB
2 years ago
|
using System;
|
||
|
using System.Linq;
|
||
|
using Microsoft.AspNetCore.Builder;
|
||
|
using Microsoft.AspNetCore.Cors;
|
||
|
using Microsoft.Extensions.Configuration;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Ocelot.DependencyInjection;
|
||
|
using Ocelot.Middleware;
|
||
|
using Volo.Abp;
|
||
|
using Volo.Abp.AspNetCore.Serilog;
|
||
|
using Volo.Abp.Autofac;
|
||
|
using Volo.Abp.Localization;
|
||
|
using Volo.Abp.Modularity;
|
||
|
using Win_in.Sfs.Shared.Host;
|
||
|
|
||
|
namespace WebAppGateway;
|
||
|
|
||
|
[DependsOn(
|
||
|
typeof(AbpAutofacModule),
|
||
|
typeof(AbpAspNetCoreSerilogModule)
|
||
|
)]
|
||
|
public class WebAppGatewayHostModule : AbpModule
|
||
|
{
|
||
|
|
||
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
||
|
{
|
||
|
var configuration = context.Services.GetConfiguration();
|
||
|
_ = context.Services.GetHostingEnvironment();
|
||
|
context.SetConsoleTitleOfWebApp("Web.Gateway");
|
||
|
|
||
|
ConfigureAuthentication(context, configuration);
|
||
|
ConfigureCors(context, configuration);
|
||
|
//ConfigureSwaggerServices(context);
|
||
|
ConfigureLocalization();
|
||
|
context.Services.AddOcelot(context.Services.GetConfiguration());
|
||
|
}
|
||
|
|
||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||
|
{
|
||
|
var app = context.GetApplicationBuilder();
|
||
|
|
||
|
app.UseCorrelationId();
|
||
|
app.UseRouting();
|
||
|
app.UseCors();
|
||
|
app.UseAuthentication();
|
||
|
app.UseAbpClaimsMap();
|
||
|
app.UseAuthorization();
|
||
|
|
||
|
//app.UseSwagger();
|
||
|
//app.UseSwaggerUI(options =>
|
||
|
//{
|
||
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "Business Service API");
|
||
|
//});
|
||
|
|
||
|
app.UseOcelot().Wait();
|
||
|
app.UseAbpSerilogEnrichers();
|
||
|
}
|
||
|
|
||
|
private static void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
|
||
|
{
|
||
|
context.Services.AddAuthentication("Bearer")
|
||
|
.AddIdentityServerAuthentication(options =>
|
||
|
{
|
||
|
options.Authority = configuration["AuthServer:Authority"];
|
||
|
options.RequireHttpsMetadata = false;
|
||
|
options.ApiName = "WebAppGateway";
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
|
||
|
{
|
||
|
context.Services.AddSwaggerGen(
|
||
|
options =>
|
||
|
{
|
||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAppGateway Service API", Version = "v1" });
|
||
|
options.DocInclusionPredicate((docName, description) => true);
|
||
|
});
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
private void ConfigureLocalization()
|
||
|
{
|
||
|
Configure<AbpLocalizationOptions>(options =>
|
||
|
{
|
||
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
private static void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
|
||
|
{
|
||
|
var origins = configuration.GetSection("App:CorsOrigins").Get<string[]>();
|
||
|
|
||
|
context.Services.AddCors(options =>
|
||
|
{
|
||
|
options.AddDefaultPolicy(builder =>
|
||
|
{
|
||
|
builder
|
||
|
.WithOrigins(
|
||
|
origins.Select(o => o.RemovePostFix("/"))
|
||
|
.ToArray()
|
||
|
)
|
||
|
.WithAbpExposedHeaders()
|
||
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||
|
.AllowAnyHeader()
|
||
|
.AllowAnyMethod()
|
||
|
.AllowCredentials();
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|