1- use axum:: extract:: { Request , State } ;
2- use axum:: middleware;
1+ use axum:: extract:: State ;
32use axum:: routing:: { get, post} ;
43use axum:: { Json , Router } ;
54use bytes:: Bytes ;
@@ -47,9 +46,7 @@ pub fn router(state: AppState) -> Router {
4746 }
4847 } ) ;
4948
50- let serve_dir = ServeDir :: new ( & static_dir)
51- . redirect_to_trailing_slash ( false )
52- . not_found_service ( spa_fallback) ;
49+ let serve_dir = ServeDir :: new ( & static_dir) . not_found_service ( spa_fallback) ;
5350
5451 Router :: new ( )
5552 . route ( "/health" , get ( health) )
@@ -69,28 +66,11 @@ pub fn router(state: AppState) -> Router {
6966 . nest ( "/auth" , crate :: auth:: routes:: routes ( ) )
7067 . route ( "/oauth/client-metadata.json" , get ( client_metadata) )
7168 . fallback_service ( serve_dir)
72- . layer ( middleware:: map_request ( trim_trailing_slash) )
7369 . layer ( TraceLayer :: new_for_http ( ) )
7470 . layer ( CorsLayer :: permissive ( ) )
7571 . with_state ( state)
7672}
7773
78- async fn trim_trailing_slash ( mut req : Request ) -> Request {
79- let path = req. uri ( ) . path ( ) ;
80- if path. len ( ) > 1 && path. ends_with ( '/' ) {
81- let new_path = path. trim_end_matches ( '/' ) ;
82- let mut parts = req. uri ( ) . clone ( ) . into_parts ( ) ;
83- let new_pq = if let Some ( q) = req. uri ( ) . query ( ) {
84- format ! ( "{new_path}?{q}" )
85- } else {
86- new_path. to_string ( )
87- } ;
88- parts. path_and_query = Some ( new_pq. parse ( ) . unwrap ( ) ) ;
89- * req. uri_mut ( ) = axum:: http:: Uri :: from_parts ( parts) . unwrap ( ) ;
90- }
91- req
92- }
93-
9474async fn health ( ) -> Json < serde_json:: Value > {
9575 Json ( serde_json:: json!( { "status" : "ok" } ) )
9676}
0 commit comments