From 55912832bf2ddadea9d000e09afea90e33f60802 Mon Sep 17 00:00:00 2001 From: ospab Date: Tue, 26 May 2026 22:27:13 +0300 Subject: [PATCH] fix: use proper axum 0.8 wildcard syntax to fix runtime panic --- ostp-server/src/api.rs | 46 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/ostp-server/src/api.rs b/ostp-server/src/api.rs index fbca15a..9b45989 100644 --- a/ostp-server/src/api.rs +++ b/ostp-server/src/api.rs @@ -231,7 +231,7 @@ pub fn create_api_router(state: ApiState) -> Router { })) // /{webpath}/ and /{webpath}/** → serve embedded static files .route(&format!("{}/", base_route), get(static_handler.clone())) - .route(&format!("{}/*path", base_route), get(static_handler)) + .route(&format!("{}/{{*path}}", base_route), get(static_handler)) // /{webpath}/api/* → API handlers .nest(&format!("{}/api", base_route), api_router) .layer(cors) @@ -777,3 +777,47 @@ async fn handle_subscribe( "data": config }))) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_router_creation() { + let state = ApiState { + access_keys: Arc::new(RwLock::new(HashMap::new())), + user_stats: Arc::new(RwLock::new(HashMap::new())), + start_time: std::time::Instant::now(), + session_token: Arc::new(RwLock::new(None)), + webpath: "bNAzr8Ss".to_string(), + username: "admin".to_string(), + password_hash: "hash".to_string(), + server_host: "127.0.0.1".to_string(), + server_port: 50000, + reality_query: "".to_string(), + config_path: None, + }; + // This should not panic + let _router = create_api_router(state); + } + + #[test] + fn test_router_creation_empty_webpath() { + let state = ApiState { + access_keys: Arc::new(RwLock::new(HashMap::new())), + user_stats: Arc::new(RwLock::new(HashMap::new())), + start_time: std::time::Instant::now(), + session_token: Arc::new(RwLock::new(None)), + webpath: "".to_string(), + username: "admin".to_string(), + password_hash: "hash".to_string(), + server_host: "127.0.0.1".to_string(), + server_port: 50000, + reality_query: "".to_string(), + config_path: None, + }; + // This should not panic + let _router = create_api_router(state); + } +} +