Browse Source

feat: 调整模板

pull/148/head 9.3.4.3
zzzwangjun@gmail.com 6 months ago
parent
commit
5f059107fa
  1. 55
      templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/AbpProWebGatewayModule.cs
  2. 26
      templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/MyProjectNameWebGatewayModule.cs
  3. 9
      templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/Program.cs
  4. 48
      templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/appsettings.Consul.json
  5. 26
      templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/appsettings.Production.json
  6. 24
      templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/appsettings.json

55
templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/AbpProWebGatewayModule.cs

@ -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();
});
});
}
}
}

26
templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/MyProjectNameWebGatewayModule.cs

@ -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();
}
}

9
templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/Program.cs

@ -1,13 +1,14 @@
namespace Lion.AbpPro.WebGateway
using Lion.AbpPro.WebGateway;
namespace MyCompanyName.MyProjectName.WebGateway
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host
.UseAutofac();
await builder.AddApplicationAsync<AbpProWebGatewayModule>();
builder.Host.UseAutofac();
await builder.AddApplicationAsync<MyProjectNameWebGatewayModule>();
var app = builder.Build();
await app.InitializeApplicationAsync();
await app.RunAsync();

48
templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/appsettings.Consul.json

@ -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"
]
}
]
}

26
templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/appsettings.Production.json

@ -7,22 +7,16 @@
}
},
"AllowedHosts": "*",
"App": {
"SelfUrl": "http://localhost:44314",
"CorsOrigins": "http://*:*,https://*,http://*,http://localhost"
},
"GlobalConfiguration": {
},
"Routes": [
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "lion.abp.pro",
"Port": 8080
}
],
"ServiceName": "MyCompanyName.MyProjectName.Api",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UpstreamPathTemplate": "/gateway/{url}",
"UpstreamHttpMethod": [
"Get",
@ -34,12 +28,10 @@
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "ws",
"DownstreamHostAndPorts": [
{
"Host": "lion.abp.pro",
"Port": 8080
}
],
"ServiceName": "MyCompanyName.MyProjectName.Api",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UpstreamPathTemplate": "/ws/{url}",
"UpstreamHttpMethod": [
"Get",
@ -49,4 +41,4 @@
]
}
]
}
}

24
templates/pro-nuget/service/host/MyCompanyName.MyProjectName.WebGateway/appsettings.json

@ -7,22 +7,16 @@
}
},
"AllowedHosts": "*",
"App": {
"SelfUrl": "http://localhost:44314",
"CorsOrigins": "http://localhost:4200"
},
"GlobalConfiguration": {
},
"Routes": [
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44315
}
],
"ServiceName": "MyCompanyName.MyProjectName.Api",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UpstreamPathTemplate": "/gateway/{url}",
"UpstreamHttpMethod": [
"Get",
@ -34,12 +28,10 @@
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "ws",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44315
}
],
"ServiceName": "MyCompanyName.MyProjectName.Api",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UpstreamPathTemplate": "/ws/{url}",
"UpstreamHttpMethod": [
"Get",

Loading…
Cancel
Save