chore: 优化authserver代码
This commit is contained in:
14
applications/KonSoft.AuthServer/Controller/HomeController.cs
Normal file
14
applications/KonSoft.AuthServer/Controller/HomeController.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Volo.Abp.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace KonSoft.Controller
|
||||||
|
{
|
||||||
|
public class HomeController : AbpController
|
||||||
|
{
|
||||||
|
[HttpGet("health")]
|
||||||
|
public ActionResult Health()
|
||||||
|
{
|
||||||
|
return Ok("online");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -59,6 +59,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\modules\admin\src\KonSoft.Admin.Application\KonSoft.Admin.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\..\modules\admin\src\KonSoft.Admin.EntityFrameworkCore\KonSoft.Admin.EntityFrameworkCore.csproj" />
|
||||||
<ProjectReference Include="..\..\shared\KonSoft.Shared.Hosting.Microservices\KonSoft.Shared.Hosting.Microservices.csproj" />
|
<ProjectReference Include="..\..\shared\KonSoft.Shared.Hosting.Microservices\KonSoft.Shared.Hosting.Microservices.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
using KonSoft.Admin;
|
||||||
|
using KonSoft.Admin.EntityFrameworkCore;
|
||||||
using KonSoft.Shared.Hosting.AspNetCore;
|
using KonSoft.Shared.Hosting.AspNetCore;
|
||||||
using KonSoft.Shared.Hosting.Microservices;
|
using KonSoft.Shared.Hosting.Microservices;
|
||||||
using KonSoft.Shared.Localization.Localization;
|
using KonSoft.Shared.Localization.Localization;
|
||||||
@ -10,6 +12,7 @@ using Volo.Abp.Account;
|
|||||||
using Volo.Abp.Account.Localization;
|
using Volo.Abp.Account.Localization;
|
||||||
using Volo.Abp.Account.Web;
|
using Volo.Abp.Account.Web;
|
||||||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
|
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
|
||||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
|
||||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
|
||||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
|
||||||
using Volo.Abp.Auditing;
|
using Volo.Abp.Auditing;
|
||||||
@ -25,6 +28,9 @@ namespace KonSoft;
|
|||||||
typeof(AbpAccountWebOpenIddictModule),
|
typeof(AbpAccountWebOpenIddictModule),
|
||||||
typeof(AbpAccountApplicationModule),
|
typeof(AbpAccountApplicationModule),
|
||||||
typeof(AbpAccountHttpApiModule),
|
typeof(AbpAccountHttpApiModule),
|
||||||
|
typeof(AdminApplicationModule),
|
||||||
|
typeof(AdminEntityFrameworkCoreModule),
|
||||||
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule),
|
||||||
typeof(KonSoftSharedHostingMicroservicesModule)
|
typeof(KonSoftSharedHostingMicroservicesModule)
|
||||||
)]
|
)]
|
||||||
public class KonSoftAuthServerModule : AbpModule
|
public class KonSoftAuthServerModule : AbpModule
|
||||||
@ -54,7 +60,7 @@ public class KonSoftAuthServerModule : AbpModule
|
|||||||
PreConfigure<OpenIddictServerBuilder>(serverBuilder =>
|
PreConfigure<OpenIddictServerBuilder>(serverBuilder =>
|
||||||
{
|
{
|
||||||
serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx",
|
serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx",
|
||||||
"59464dba-b66e-48cd-8b81-2e4a9c08c977");
|
configuration["Certificate:Password"]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
using System;
|
using KonSoft.Shared.Hosting.AspNetCore;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Events;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace KonSoft;
|
namespace KonSoft;
|
||||||
|
|
||||||
@ -12,45 +10,27 @@ public class Program
|
|||||||
{
|
{
|
||||||
public static async Task<int> Main(string[] args)
|
public static async Task<int> Main(string[] args)
|
||||||
{
|
{
|
||||||
Log.Logger = new LoggerConfiguration()
|
var assemblyName = typeof(Program).Assembly.GetName().Name!;
|
||||||
#if DEBUG
|
|
||||||
.MinimumLevel.Debug()
|
|
||||||
#else
|
|
||||||
.MinimumLevel.Information()
|
|
||||||
#endif
|
|
||||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
||||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Async(c => c.File("Logs/logs.txt"))
|
|
||||||
.WriteTo.Async(c => c.Console())
|
|
||||||
.CreateLogger();
|
|
||||||
|
|
||||||
|
SerilogConfigurationHelper.Configure(assemblyName);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Log.Information("Starting KonSoft.AuthServer.");
|
Log.Information($"Starting {assemblyName}.");
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var app = await ApplicationBuilderHelper
|
||||||
builder.Host.AddAppSettingsSecretsJson()
|
.BuildApplicationAsync<KonSoftAuthServerModule>(args);
|
||||||
.UseAutofac()
|
|
||||||
.UseSerilog();
|
|
||||||
await builder.AddApplicationAsync<KonSoftAuthServerModule>();
|
|
||||||
var app = builder.Build();
|
|
||||||
await app.InitializeApplicationAsync();
|
await app.InitializeApplicationAsync();
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (ex is HostAbortedException)
|
Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!");
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Fatal(ex, "KonSoft.AuthServer terminated unexpectedly!");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Log.CloseAndFlush();
|
await Log.CloseAndFlushAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,17 +1,8 @@
|
|||||||
{
|
{
|
||||||
"App": {
|
"AgileConfig": {
|
||||||
"SelfUrl": "https://localhost:44322",
|
"appId": "KonSoft.Admin.HttpApi.Host",
|
||||||
"ClientUrl": "http://localhost:4200",
|
"name": "KonSoft.Admin.HttpApi.Host",
|
||||||
"CorsOrigins": "https://*.KonSoft.com,http://localhost:4200,https://localhost:44316,https://localhost:44370",
|
"nodes": "https://config.konsoft.top/",
|
||||||
"RedirectAllowedUrls": "http://localhost:4200,https://localhost:44319,https://localhost:44316,https://localhost:44347"
|
"secret": "DBE31703-14F9-4B01-893D-900B8380CE04"
|
||||||
},
|
|
||||||
"ConnectionStrings": {
|
|
||||||
"Default": "Host=localhost;Port=5432;Database=KonSoft;User ID=root;Password=myPassword;"
|
|
||||||
},
|
|
||||||
"Redis": {
|
|
||||||
"Configuration": "127.0.0.1"
|
|
||||||
},
|
|
||||||
"StringEncryption": {
|
|
||||||
"DefaultPassPhrase": "kxtywyrXW4i7vijT"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
internalgateways:
|
internalgateways:
|
||||||
container_name: clean-internalgateways
|
container_name: clean-internalgateways
|
||||||
restart: always
|
restart: unless-stopped
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./gateways/KonSoft.InternalGateway/Dockerfile
|
dockerfile: ./gateways/KonSoft.InternalGateway/Dockerfile
|
||||||
@ -15,10 +15,21 @@ services:
|
|||||||
- 8080:8080
|
- 8080:8080
|
||||||
networks:
|
networks:
|
||||||
- konsoft-shared-network
|
- konsoft-shared-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8081/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
authserver:
|
authserver:
|
||||||
container_name: clean-authserver
|
container_name: clean-authserver
|
||||||
restart: always
|
restart: unless-stopped
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./applications/KonSoft.AuthServer/Dockerfile
|
dockerfile: ./applications/KonSoft.AuthServer/Dockerfile
|
||||||
@ -30,12 +41,25 @@ services:
|
|||||||
- AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04
|
- AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04
|
||||||
ports:
|
ports:
|
||||||
- 8081:8081
|
- 8081:8081
|
||||||
|
volumes:
|
||||||
|
- /root/openiddict.pfx:/app/openiddict.pfx:ro
|
||||||
networks:
|
networks:
|
||||||
- konsoft-shared-network
|
- konsoft-shared-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
adminservice:
|
adminservice:
|
||||||
container_name: clean-adminservice
|
container_name: clean-adminservice
|
||||||
restart: always
|
restart: unless-stopped
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./microservices/KonSoft.Admin.HttpApi.Host/Dockerfile
|
dockerfile: ./microservices/KonSoft.Admin.HttpApi.Host/Dockerfile
|
||||||
@ -47,6 +71,17 @@ services:
|
|||||||
- AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04
|
- AgileConfig__Secret=DBE31703-14F9-4B01-893D-900B8380CE04
|
||||||
networks:
|
networks:
|
||||||
- konsoft-shared-network
|
- konsoft-shared-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
konsoft-shared-network:
|
konsoft-shared-network:
|
||||||
|
|||||||
@ -9,4 +9,10 @@ public class HomeController : AbpController
|
|||||||
{
|
{
|
||||||
return Redirect("~/swagger");
|
return Redirect("~/swagger");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("health")]
|
||||||
|
public ActionResult Health()
|
||||||
|
{
|
||||||
|
return Ok("online");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -9,4 +9,11 @@ public class HomeController : AbpController
|
|||||||
{
|
{
|
||||||
return Redirect("~/swagger");
|
return Redirect("~/swagger");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("health")]
|
||||||
|
public ActionResult Health()
|
||||||
|
{
|
||||||
|
return Ok("online");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -9,4 +9,11 @@ public class HomeController : AbpController
|
|||||||
{
|
{
|
||||||
return Redirect("~/swagger");
|
return Redirect("~/swagger");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("health")]
|
||||||
|
public ActionResult Health()
|
||||||
|
{
|
||||||
|
return Ok("online");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -9,4 +9,11 @@ public class HomeController : AbpController
|
|||||||
{
|
{
|
||||||
return Redirect("~/swagger");
|
return Redirect("~/swagger");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("health")]
|
||||||
|
public ActionResult Health()
|
||||||
|
{
|
||||||
|
return Ok("online");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -9,4 +9,11 @@ public class HomeController : AbpController
|
|||||||
{
|
{
|
||||||
return Redirect("~/swagger");
|
return Redirect("~/swagger");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("health")]
|
||||||
|
public ActionResult Health()
|
||||||
|
{
|
||||||
|
return Ok("online");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -56,13 +56,14 @@ public class KonSoftSharedHostingMicroservicesModule : AbpModule
|
|||||||
ServiceConfigurationContext context,
|
ServiceConfigurationContext context,
|
||||||
IConfiguration configuration)
|
IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
var redisConnStr = configuration["Redis:Configuration"]!;
|
||||||
context.Services.AddDataProtection().SetApplicationName("KonSoft")
|
context.Services.AddDataProtection().SetApplicationName("KonSoft")
|
||||||
.PersistKeysToStackExchangeRedis(ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!),
|
.PersistKeysToStackExchangeRedis(ConnectionMultiplexer.Connect(redisConnStr),
|
||||||
"KonSoft-Protection-Keys");
|
"KonSoft-Protection-Keys");
|
||||||
|
|
||||||
context.Services.AddSingleton<IDistributedLockProvider>(_ =>
|
context.Services.AddSingleton<IDistributedLockProvider>(_ =>
|
||||||
new RedisDistributedSynchronizationProvider(ConnectionMultiplexer
|
new RedisDistributedSynchronizationProvider(ConnectionMultiplexer
|
||||||
.Connect(configuration["Redis:Configuration"]!).GetDatabase()));
|
.Connect(redisConnStr).GetDatabase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
|
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
|
||||||
|
|||||||
Reference in New Issue
Block a user