Files
KonSoft.Clean/gateways/KonSoft.InternalGateway/Program.cs
2025-10-26 22:13:17 +08:00

62 lines
1.7 KiB
C#

using KonSoft.InternalGateway;
using KonSoft.InternalGateway.Extensions;
using KonSoft.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Serilog;
var assemblyName = typeof(Program).Assembly.GetName().Name!;
SerilogConfigurationHelper.Configure(assemblyName);
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration
.AddAgileConfig(option =>
{
option.ENV = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
});
builder.Host
.AddAppSettingsSecretsJson()
.UseAutofac()
.UseSerilog();
builder.Services.AddAbpSwaggerGenWithOAuth(builder.Configuration["AuthServer:Authority"]!,
new Dictionary<string, string>
{
{ "Clean", "Clean API" }
}, options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Gateway",
Version = "v1"
});
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
builder.Services.AddControllers();
await builder.AddApplicationAsync<InternalGatewayModule>();
var app = builder.Build();
await app.InitializeApplicationAsync();
app.UseSwaggerUIWithYarp();
app.MapReverseProxy();
app.MapGet("/heath", () => "Online");
await app.RunAsync();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!");
return 1;
}
finally
{
await Log.CloseAndFlushAsync();
}