chore: 关闭生产Swagger并移除网关转发
This commit is contained in:
@@ -23,6 +23,7 @@ using TakeoutSaaS.Shared.Web.Swagger;
|
|||||||
// 1. 创建构建器与日志模板
|
// 1. 创建构建器与日志模板
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
const string logTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] [TraceId:{TraceId}] [SpanId:{SpanId}] [Service:{Service}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
const string logTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] [TraceId:{TraceId}] [SpanId:{SpanId}] [Service:{Service}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
||||||
|
var isDevelopment = builder.Environment.IsDevelopment();
|
||||||
|
|
||||||
// 2. 加载种子配置文件
|
// 2. 加载种子配置文件
|
||||||
builder.Configuration
|
builder.Configuration
|
||||||
@@ -44,14 +45,17 @@ builder.Host.UseSerilog((context, _, configuration) =>
|
|||||||
outputTemplate: logTemplate);
|
outputTemplate: logTemplate);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. 注册通用 Web 能力与 Swagger
|
// 4. 注册通用 Web 能力,开发环境启用 Swagger
|
||||||
builder.Services.AddSharedWebCore();
|
builder.Services.AddSharedWebCore();
|
||||||
builder.Services.AddSharedSwagger(options =>
|
if (isDevelopment)
|
||||||
{
|
{
|
||||||
|
builder.Services.AddSharedSwagger(options =>
|
||||||
|
{
|
||||||
options.Title = "外卖SaaS - 管理后台";
|
options.Title = "外卖SaaS - 管理后台";
|
||||||
options.Description = "管理后台 API 文档";
|
options.Description = "管理后台 API 文档";
|
||||||
options.EnableAuthorization = true;
|
options.EnableAuthorization = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 5. 注册领域与基础设施模块
|
// 5. 注册领域与基础设施模块
|
||||||
builder.Services.AddIdentityApplication();
|
builder.Services.AddIdentityApplication();
|
||||||
@@ -139,7 +143,10 @@ app.UseTenantResolution();
|
|||||||
app.UseSharedWebCore();
|
app.UseSharedWebCore();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseSharedSwagger();
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSharedSwagger();
|
||||||
|
}
|
||||||
app.UseSchedulerDashboard(builder.Configuration);
|
app.UseSchedulerDashboard(builder.Configuration);
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
app.MapPrometheusScrapingEndpoint();
|
app.MapPrometheusScrapingEndpoint();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ using System.Reflection;
|
|||||||
// 1. 创建构建器与日志模板
|
// 1. 创建构建器与日志模板
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
const string logTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] [TraceId:{TraceId}] [SpanId:{SpanId}] [Service:{Service}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
const string logTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] [TraceId:{TraceId}] [SpanId:{SpanId}] [Service:{Service}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
||||||
|
var isDevelopment = builder.Environment.IsDevelopment();
|
||||||
|
|
||||||
// 2. 注册雪花 ID 生成器与 Serilog
|
// 2. 注册雪花 ID 生成器与 Serilog
|
||||||
builder.Services.AddSingleton<IIdGenerator>(_ => new SnowflakeIdGenerator());
|
builder.Services.AddSingleton<IIdGenerator>(_ => new SnowflakeIdGenerator());
|
||||||
@@ -38,14 +39,17 @@ builder.Host.UseSerilog((_, _, configuration) =>
|
|||||||
outputTemplate: logTemplate);
|
outputTemplate: logTemplate);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. 注册通用 Web 能力与 Swagger
|
// 3. 注册通用 Web 能力,开发环境启用 Swagger
|
||||||
builder.Services.AddSharedWebCore();
|
builder.Services.AddSharedWebCore();
|
||||||
builder.Services.AddSharedSwagger(options =>
|
if (isDevelopment)
|
||||||
{
|
{
|
||||||
|
builder.Services.AddSharedSwagger(options =>
|
||||||
|
{
|
||||||
options.Title = "外卖SaaS - 小程序端";
|
options.Title = "外卖SaaS - 小程序端";
|
||||||
options.Description = "小程序 API 文档";
|
options.Description = "小程序 API 文档";
|
||||||
options.EnableAuthorization = true;
|
options.EnableAuthorization = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
// 4. 注册 Redis 分布式缓存,供验证码等功能使用
|
// 4. 注册 Redis 分布式缓存,供验证码等功能使用
|
||||||
@@ -133,7 +137,10 @@ var app = builder.Build();
|
|||||||
app.UseCors("MiniApiCors");
|
app.UseCors("MiniApiCors");
|
||||||
app.UseTenantResolution();
|
app.UseTenantResolution();
|
||||||
app.UseSharedWebCore();
|
app.UseSharedWebCore();
|
||||||
app.UseSharedSwagger();
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSharedSwagger();
|
||||||
|
}
|
||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
app.MapPrometheusScrapingEndpoint();
|
app.MapPrometheusScrapingEndpoint();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using TakeoutSaaS.Shared.Web.Swagger;
|
|||||||
// 1. 创建构建器与日志模板
|
// 1. 创建构建器与日志模板
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
const string logTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] [TraceId:{TraceId}] [SpanId:{SpanId}] [Service:{Service}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
const string logTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] [TraceId:{TraceId}] [SpanId:{SpanId}] [Service:{Service}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
||||||
|
var isDevelopment = builder.Environment.IsDevelopment();
|
||||||
|
|
||||||
// 2. 注册雪花 ID 生成器与 Serilog
|
// 2. 注册雪花 ID 生成器与 Serilog
|
||||||
builder.Services.AddSingleton<IIdGenerator>(_ => new SnowflakeIdGenerator());
|
builder.Services.AddSingleton<IIdGenerator>(_ => new SnowflakeIdGenerator());
|
||||||
@@ -29,14 +30,17 @@ builder.Host.UseSerilog((_, _, configuration) =>
|
|||||||
outputTemplate: logTemplate);
|
outputTemplate: logTemplate);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. 注册通用 Web 能力与 Swagger
|
// 3. 注册通用 Web 能力,开发环境启用 Swagger
|
||||||
builder.Services.AddSharedWebCore();
|
builder.Services.AddSharedWebCore();
|
||||||
builder.Services.AddSharedSwagger(options =>
|
if (isDevelopment)
|
||||||
{
|
{
|
||||||
|
builder.Services.AddSharedSwagger(options =>
|
||||||
|
{
|
||||||
options.Title = "外卖SaaS - 用户端";
|
options.Title = "外卖SaaS - 用户端";
|
||||||
options.Description = "C 端用户 API 文档";
|
options.Description = "C 端用户 API 文档";
|
||||||
options.EnableAuthorization = true;
|
options.EnableAuthorization = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 4. 注册多租户与健康检查
|
// 4. 注册多租户与健康检查
|
||||||
builder.Services.AddTenantResolution(builder.Configuration);
|
builder.Services.AddTenantResolution(builder.Configuration);
|
||||||
@@ -110,7 +114,10 @@ var app = builder.Build();
|
|||||||
app.UseCors("UserApiCors");
|
app.UseCors("UserApiCors");
|
||||||
app.UseTenantResolution();
|
app.UseTenantResolution();
|
||||||
app.UseSharedWebCore();
|
app.UseSharedWebCore();
|
||||||
app.UseSharedSwagger();
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSharedSwagger();
|
||||||
|
}
|
||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
app.MapPrometheusScrapingEndpoint();
|
app.MapPrometheusScrapingEndpoint();
|
||||||
|
|||||||
@@ -8,20 +8,6 @@
|
|||||||
"ClusterId": "admin",
|
"ClusterId": "admin",
|
||||||
"Match": { "Path": "/api/admin/{**catch-all}" }
|
"Match": { "Path": "/api/admin/{**catch-all}" }
|
||||||
},
|
},
|
||||||
"admin-swagger": {
|
|
||||||
"ClusterId": "admin",
|
|
||||||
"Match": { "Path": "/api/admin/swagger/{**catch-all}" },
|
|
||||||
"Transforms": [
|
|
||||||
{ "PathRemovePrefix": "/api/admin" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"admin-swagger-v": {
|
|
||||||
"ClusterId": "admin",
|
|
||||||
"Match": { "Path": "/api/admin/v{version}/swagger/{**catch-all}" },
|
|
||||||
"Transforms": [
|
|
||||||
{ "PathPattern": "/swagger/{**catch-all}" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"mini-route": {
|
"mini-route": {
|
||||||
"ClusterId": "mini",
|
"ClusterId": "mini",
|
||||||
"Match": { "Path": "/api/mini/{**catch-all}" }
|
"Match": { "Path": "/api/mini/{**catch-all}" }
|
||||||
|
|||||||
@@ -41,20 +41,6 @@
|
|||||||
"ClusterId": "admin",
|
"ClusterId": "admin",
|
||||||
"Match": { "Path": "/api/admin/{**catch-all}" }
|
"Match": { "Path": "/api/admin/{**catch-all}" }
|
||||||
},
|
},
|
||||||
"admin-swagger": {
|
|
||||||
"ClusterId": "admin",
|
|
||||||
"Match": { "Path": "/api/admin/swagger/{**catch-all}" },
|
|
||||||
"Transforms": [
|
|
||||||
{ "PathRemovePrefix": "/api/admin" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"admin-swagger-v": {
|
|
||||||
"ClusterId": "admin",
|
|
||||||
"Match": { "Path": "/api/admin/v{version}/swagger/{**catch-all}" },
|
|
||||||
"Transforms": [
|
|
||||||
{ "PathPattern": "/swagger/{**catch-all}" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"mini-route": {
|
"mini-route": {
|
||||||
"ClusterId": "mini",
|
"ClusterId": "mini",
|
||||||
"Match": { "Path": "/api/mini/{**catch-all}" }
|
"Match": { "Path": "/api/mini/{**catch-all}" }
|
||||||
|
|||||||
Reference in New Issue
Block a user