6 changed files with 48 additions and 140 deletions
@ -1,55 +0,0 @@ |
|||||
using Lion.AbpPro.AspNetCore; |
|
||||
|
|
||||
namespace Lion.AbpPro.WebGateway |
|
||||
{ |
|
||||
[DependsOn( |
|
||||
typeof(AbpProAspNetCoreModule))] |
|
||||
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(); |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,26 @@ |
|||||
|
using Lion.AbpPro.AspNetCore; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Lion.AbpPro.WebGateway; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpAspNetCoreMvcModule), |
||||
|
typeof(AbpProAspNetCoreModule))] |
||||
|
public class MyProjectNameWebGatewayModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddAbpProHealthChecks(); |
||||
|
context.Services.AddAbpProOcelot(); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
var app = context.GetApplicationBuilder(); |
||||
|
app.UseCorrelationId(); |
||||
|
app.UseRouting(); |
||||
|
app.UseConfiguredEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); }); |
||||
|
app.UseWebSockets(); |
||||
|
app.UseOcelot().Wait(); |
||||
|
} |
||||
|
} |
||||
@ -1,48 +0,0 @@ |
|||||
{ |
|
||||
"Logging": { |
|
||||
"LogLevel": { |
|
||||
"Default": "Information", |
|
||||
"Microsoft": "Warning", |
|
||||
"Microsoft.Hosting.Lifetime": "Information" |
|
||||
} |
|
||||
}, |
|
||||
"AllowedHosts": "*", |
|
||||
"App": { |
|
||||
"SelfUrl": "http://120.24.194.14:8014", |
|
||||
"CorsOrigins": "http://localhost:4200,http://120.24.194.14:8012,http://120.24.194.14:8011,http://120.24.194.14:8013" |
|
||||
}, |
|
||||
"GlobalConfiguration": { |
|
||||
}, |
|
||||
"Routes": [ |
|
||||
{ |
|
||||
"DownstreamPathTemplate": "/{url}", |
|
||||
"DownstreamScheme": "http", |
|
||||
"ServiceName": "MyProjectName-Service", |
|
||||
"LoadBalancerOptions": { |
|
||||
"Type": "LeastConnection" |
|
||||
}, |
|
||||
"UpstreamPathTemplate": "/gateway/{url}", |
|
||||
"UpstreamHttpMethod": [ |
|
||||
"Get", |
|
||||
"Post", |
|
||||
"Put", |
|
||||
"Delete" |
|
||||
] |
|
||||
}, |
|
||||
{ |
|
||||
"DownstreamPathTemplate": "/{url}", |
|
||||
"DownstreamScheme": "ws", |
|
||||
"ServiceName": "MyProjectName-Service", |
|
||||
"LoadBalancerOptions": { |
|
||||
"Type": "LeastConnection" |
|
||||
}, |
|
||||
"UpstreamPathTemplate": "/ws/{url}", |
|
||||
"UpstreamHttpMethod": [ |
|
||||
"Get", |
|
||||
"Post", |
|
||||
"Put", |
|
||||
"Delete" |
|
||||
] |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
Loading…
Reference in new issue