chore: 关闭生产Swagger并移除网关转发

This commit is contained in:
2025-12-04 22:42:46 +08:00
parent 64a5f61a6a
commit a42f470113
5 changed files with 62 additions and 69 deletions

View File

@@ -23,6 +23,7 @@ using TakeoutSaaS.Shared.Web.Swagger;
// 1. 创建构建器与日志模板
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}";
var isDevelopment = builder.Environment.IsDevelopment();
// 2. 加载种子配置文件
builder.Configuration
@@ -44,14 +45,17 @@ builder.Host.UseSerilog((context, _, configuration) =>
outputTemplate: logTemplate);
});
// 4. 注册通用 Web 能力 Swagger
// 4. 注册通用 Web 能力,开发环境启用 Swagger
builder.Services.AddSharedWebCore();
builder.Services.AddSharedSwagger(options =>
if (isDevelopment)
{
options.Title = "外卖SaaS - 管理后台";
options.Description = "管理后台 API 文档";
options.EnableAuthorization = true;
});
builder.Services.AddSharedSwagger(options =>
{
options.Title = "外卖SaaS - 管理后台";
options.Description = "管理后台 API 文档";
options.EnableAuthorization = true;
});
}
// 5. 注册领域与基础设施模块
builder.Services.AddIdentityApplication();
@@ -139,7 +143,10 @@ app.UseTenantResolution();
app.UseSharedWebCore();
app.UseAuthentication();
app.UseAuthorization();
app.UseSharedSwagger();
if (app.Environment.IsDevelopment())
{
app.UseSharedSwagger();
}
app.UseSchedulerDashboard(builder.Configuration);
app.MapHealthChecks("/healthz");
app.MapPrometheusScrapingEndpoint();

View File

@@ -21,6 +21,7 @@ using System.Reflection;
// 1. 创建构建器与日志模板
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}";
var isDevelopment = builder.Environment.IsDevelopment();
// 2. 注册雪花 ID 生成器与 Serilog
builder.Services.AddSingleton<IIdGenerator>(_ => new SnowflakeIdGenerator());
@@ -38,14 +39,17 @@ builder.Host.UseSerilog((_, _, configuration) =>
outputTemplate: logTemplate);
});
// 3. 注册通用 Web 能力 Swagger
// 3. 注册通用 Web 能力,开发环境启用 Swagger
builder.Services.AddSharedWebCore();
builder.Services.AddSharedSwagger(options =>
if (isDevelopment)
{
options.Title = "外卖SaaS - 小程序端";
options.Description = "小程序 API 文档";
options.EnableAuthorization = true;
});
builder.Services.AddSharedSwagger(options =>
{
options.Title = "外卖SaaS - 小程序端";
options.Description = "小程序 API 文档";
options.EnableAuthorization = true;
});
}
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
// 4. 注册 Redis 分布式缓存,供验证码等功能使用
@@ -133,7 +137,10 @@ var app = builder.Build();
app.UseCors("MiniApiCors");
app.UseTenantResolution();
app.UseSharedWebCore();
app.UseSharedSwagger();
if (app.Environment.IsDevelopment())
{
app.UseSharedSwagger();
}
app.MapHealthChecks("/healthz");
app.MapPrometheusScrapingEndpoint();

View File

@@ -12,6 +12,7 @@ using TakeoutSaaS.Shared.Web.Swagger;
// 1. 创建构建器与日志模板
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}";
var isDevelopment = builder.Environment.IsDevelopment();
// 2. 注册雪花 ID 生成器与 Serilog
builder.Services.AddSingleton<IIdGenerator>(_ => new SnowflakeIdGenerator());
@@ -29,14 +30,17 @@ builder.Host.UseSerilog((_, _, configuration) =>
outputTemplate: logTemplate);
});
// 3. 注册通用 Web 能力 Swagger
// 3. 注册通用 Web 能力,开发环境启用 Swagger
builder.Services.AddSharedWebCore();
builder.Services.AddSharedSwagger(options =>
if (isDevelopment)
{
options.Title = "外卖SaaS - 用户端";
options.Description = "C 端用户 API 文档";
options.EnableAuthorization = true;
});
builder.Services.AddSharedSwagger(options =>
{
options.Title = "外卖SaaS - 用户端";
options.Description = "C 端用户 API 文档";
options.EnableAuthorization = true;
});
}
// 4. 注册多租户与健康检查
builder.Services.AddTenantResolution(builder.Configuration);
@@ -110,7 +114,10 @@ var app = builder.Build();
app.UseCors("UserApiCors");
app.UseTenantResolution();
app.UseSharedWebCore();
app.UseSharedSwagger();
if (app.Environment.IsDevelopment())
{
app.UseSharedSwagger();
}
app.MapHealthChecks("/healthz");
app.MapPrometheusScrapingEndpoint();

View File

@@ -2,30 +2,16 @@
"OpenTelemetry": {
"Enabled": false
},
"ReverseProxy": {
"Routes": {
"admin-route": {
"ClusterId": "admin",
"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": {
"ClusterId": "mini",
"Match": { "Path": "/api/mini/{**catch-all}" }
},
"ReverseProxy": {
"Routes": {
"admin-route": {
"ClusterId": "admin",
"Match": { "Path": "/api/admin/{**catch-all}" }
},
"mini-route": {
"ClusterId": "mini",
"Match": { "Path": "/api/mini/{**catch-all}" }
},
"user-route": {
"ClusterId": "user",
"Match": { "Path": "/api/user/{**catch-all}" }

View File

@@ -35,30 +35,16 @@
"ServiceName": "TakeoutSaaS.ApiGateway",
"OtlpEndpoint": "http://localhost:4317"
},
"ReverseProxy": {
"Routes": {
"admin-route": {
"ClusterId": "admin",
"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": {
"ClusterId": "mini",
"Match": { "Path": "/api/mini/{**catch-all}" }
},
"ReverseProxy": {
"Routes": {
"admin-route": {
"ClusterId": "admin",
"Match": { "Path": "/api/admin/{**catch-all}" }
},
"mini-route": {
"ClusterId": "mini",
"Match": { "Path": "/api/mini/{**catch-all}" }
},
"user-route": {
"ClusterId": "user",
"Match": { "Path": "/api/user/{**catch-all}" }