2025-05-27 14:02:24 +08:00
|
|
|
namespace JiShe.ServicePro.WebGateway
|
2025-03-11 10:24:11 +08:00
|
|
|
{
|
|
|
|
|
[DependsOn(
|
2025-05-27 14:02:24 +08:00
|
|
|
typeof(ServiceProSharedHostingGatewayModule))]
|
2025-03-11 10:24:11 +08:00
|
|
|
public class AbpProWebGatewayModule : AbpModule
|
|
|
|
|
{
|
|
|
|
|
private const string DefaultCorsPolicyName = "Default";
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
|
|
|
{
|
|
|
|
|
ConfigureCors(context);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
|
|
|
{
|
|
|
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
|
app.UseCorrelationId();
|
|
|
|
|
app.UseCors(DefaultCorsPolicyName);
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
app.UseConfiguredEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); });
|
|
|
|
|
app.UseWebSockets();
|
|
|
|
|
app.UseOcelot().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 配置跨域
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ConfigureCors(ServiceConfigurationContext context)
|
|
|
|
|
{
|
|
|
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
|
context.Services.AddCors(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
|
|
|
{
|
|
|
|
|
builder
|
|
|
|
|
.WithOrigins(
|
|
|
|
|
configuration["App:CorsOrigins"]
|
|
|
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
|
.Select(o => o.RemovePostFix("/"))
|
|
|
|
|
.ToArray()
|
|
|
|
|
)
|
|
|
|
|
.WithAbpExposedHeaders()
|
|
|
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
.AllowAnyMethod()
|
|
|
|
|
.AllowCredentials();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|