17 changed files with 127 additions and 148 deletions
@ -0,0 +1,49 @@ |
|||
namespace Lion.AbpPro.AspNetCore.Options; |
|||
|
|||
public class AbpProConsulOptions |
|||
{ |
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool Enabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// consul服务地址
|
|||
/// </summary>
|
|||
public string ServiceUrl { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 服务名称
|
|||
/// </summary>
|
|||
public string ClientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 服务地址,不带端口
|
|||
/// </summary>
|
|||
public string ClientAddress { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 服务端口
|
|||
/// </summary>
|
|||
public int ClientPort { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 健康检查地址
|
|||
/// </summary>
|
|||
public string HealthUrl { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 服务停止多久后注销,单位秒
|
|||
/// </summary>
|
|||
public int DeregisterCriticalServiceAfter { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 健康检查时间间隔,或者称为心跳 间隔,单位秒
|
|||
/// </summary>
|
|||
public int Interval { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 超时时间,单位秒
|
|||
/// </summary>
|
|||
public int Timeout { get; set; } |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
namespace Lion.AbpPro.AspNetCore.Options; |
|||
|
|||
public class AbpProGatewayOptions |
|||
{ |
|||
/// <summary>
|
|||
/// 是否启用
|
|||
/// </summary>
|
|||
public bool Enabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// consul服务地址
|
|||
/// </summary>
|
|||
public string ConsulServiceUrl { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// consul服务名称
|
|||
/// </summary>
|
|||
public string ServiceName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 健康检查地址
|
|||
/// </summary>
|
|||
public string HealthUrl { get; set; } |
|||
} |
|||
@ -1,55 +1,25 @@ |
|||
using Lion.AbpPro.AspNetCore; |
|||
|
|||
namespace Lion.AbpPro.WebGateway |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpProAspNetCoreModule))] |
|||
public class AbpProWebGatewayModule : AbpModule |
|||
{ |
|||
private const string DefaultCorsPolicyName = "Default"; |
|||
namespace Lion.AbpPro.WebGateway; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreMvcModule), |
|||
typeof(AbpProAspNetCoreModule))] |
|||
public class AbpProWebGatewayModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
ConfigureCors(context); |
|||
|
|||
context.Services.AddAbpProHealthChecks(); |
|||
context.Services.AddAbpProOcelot(); |
|||
} |
|||
|
|||
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(); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -1,16 +1,14 @@ |
|||
namespace Lion.AbpPro.WebGateway |
|||
namespace Lion.AbpPro.WebGateway; |
|||
|
|||
public class Program |
|||
{ |
|||
public class Program |
|||
{ |
|||
public static async Task Main(string[] args) |
|||
{ |
|||
var builder = WebApplication.CreateBuilder(args); |
|||
builder.Host |
|||
.UseAutofac(); |
|||
builder.Host .UseAutofac(); |
|||
await builder.AddApplicationAsync<AbpProWebGatewayModule>(); |
|||
var app = builder.Build(); |
|||
await app.InitializeApplicationAsync(); |
|||
await app.RunAsync(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue