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 -3
View File
@@ -43,19 +43,19 @@ pub fn build_router_with_state(state: AppState) -> Router {
middleware::frontdoor_cors_middleware,
));
}
router
middleware::apply_cf_header_stripping(router)
}
pub fn attach_static_frontend(router: Router, static_dir: impl Into<PathBuf>) -> Router {
let static_dir = static_dir.into();
let index_html = static_dir.join("index.html");
router.layer(axum::middleware::from_fn_with_state(
middleware::apply_cf_header_stripping(router.layer(axum::middleware::from_fn_with_state(
FrontendStaticState {
static_dir,
index_html,
},
frontend_static_middleware,
))
)))
}
async fn frontend_static_middleware(