@@ -19,6 +19,7 @@ use axum::{
1919 Router , TypedHeader ,
2020} ;
2121
22+ use tower:: Layer ;
2223use tower:: ServiceBuilder ;
2324use tower_http:: normalize_path:: NormalizePathLayer ;
2425use tower_http:: trace:: TraceLayer ;
@@ -54,9 +55,7 @@ impl IntoResponse for models::Response {
5455/// * a [tower_http::trace::TraceLayer] for tracing requests and responses
5556/// * a [tower_http::validate_request::ValidateRequestHeaderLayer] for validating authorisation
5657/// headers
57- /// * a [tower_http::normalize_path::NormalizePathLayer] for trimming trailing slashes from
58- /// requests
59- pub fn router ( ) -> Router {
58+ fn router ( ) -> Router {
6059 fn v1 ( ) -> Router {
6160 Router :: new ( )
6261 . route ( "/count" , post ( operation_handler :: < operations:: Count > ) )
@@ -85,7 +84,25 @@ pub fn router() -> Router {
8584 Router :: new ( )
8685 . route ( "/.well-known/s3-active-storage-schema" , get ( schema) )
8786 . nest ( "/v1" , v1 ( ) )
88- . layer ( NormalizePathLayer :: trim_trailing_slash ( ) )
87+ }
88+
89+ /// Returns a [tower_service::Service] for the Active Storage server API
90+ ///
91+ /// The service is populated with all routes as well as the following middleware:
92+ ///
93+ /// * a [tower_http::trace::TraceLayer] for tracing requests and responses
94+ /// * a [tower_http::validate_request::ValidateRequestHeaderLayer] for validating authorisation
95+ /// headers
96+ /// * a [tower_http::normalize_path::NormalizePathLayer] for trimming trailing slashes from
97+ /// requests
98+ pub fn service ( ) -> tower_http:: normalize_path:: NormalizePath < Router > {
99+ // FIXME: The return type should be some form of tower_service::Service, but couldn't find the
100+ // necessary trait bounds.
101+
102+ // Note that any middleware that should affect routing must wrap the router.
103+ // See
104+ // https://docs.rs/axum/0.6.18/axum/middleware/index.html#rewriting-request-uri-in-middleware.
105+ NormalizePathLayer :: trim_trailing_slash ( ) . layer ( router ( ) )
89106}
90107
91108/// TODO: Return an OpenAPI schema
0 commit comments