refactor(gateway): 将 CF 头剥离中间件下移至各 router 构建函数并重构为前缀匹配

This commit is contained in:
fawney19
2026-04-22 21:10:16 +08:00
parent cf6228f525
commit c8d7dbd8d6
6 changed files with 166 additions and 56 deletions
+3 -9
View File
@@ -959,20 +959,14 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
let frontdoor_health_url = format!("{public_base_url}/_gateway/health");
let api_router = build_router_with_state(state);
// Compose the final router: API routes + optional static file serving + CF header stripping
// Compose the final router: API routes + optional static file serving.
let router = if let Some(ref static_dir) = args.static_dir {
use tower_http::compression::CompressionLayer;
info!(static_dir = %static_dir, "serving frontend static files");
attach_static_frontend(api_router, static_dir)
.layer(CompressionLayer::new())
.layer(axum::middleware::from_fn(
aether_gateway::strip_cf_headers_middleware,
))
attach_static_frontend(api_router, static_dir).layer(CompressionLayer::new())
} else {
api_router.layer(axum::middleware::from_fn(
aether_gateway::strip_cf_headers_middleware,
))
api_router
};
info!(