11use std:: io:: Read ;
22
3- use axum:: { response:: IntoResponse , routing:: get, Router } ;
3+ use axum:: { http :: Uri , response:: IntoResponse , routing:: get, Router } ;
44use axum_insights:: AppInsights ;
55use futures:: TryStreamExt ;
66use leptos:: config:: get_configuration;
@@ -59,16 +59,7 @@ async fn handle(wasi_request: IncomingRequest, wasi_response_outparam: ResponseO
5959 move || shell ( leptos_options. clone ( ) )
6060 } )
6161 . route ( "/api/hello/:name" , get ( hello) )
62- . fallback ( |uri : axum:: http:: Uri | async move {
63- let path = uri. path ( ) . split_at ( 1 ) . 1 ;
64-
65- StaticAssets :: get ( path)
66- . map ( |file| ( axum:: http:: StatusCode :: OK , [ ( axum:: http:: header:: CONTENT_TYPE , file. metadata . mimetype ( ) ) ] , file. data ) . into_response ( ) )
67- . unwrap_or_else ( || {
68- println ! ( "No route matched, returning 404!: {uri}." ) ;
69- ( axum:: http:: StatusCode :: NOT_FOUND , "Not Found" . to_string ( ) ) . into_response ( )
70- } )
71- } )
62+ . fallback ( static_fallback)
7263 . layer ( telemetry_layer)
7364 . with_state ( leptos_options) ;
7465
@@ -79,6 +70,17 @@ async fn handle(wasi_request: IncomingRequest, wasi_response_outparam: ResponseO
7970 Ok ( ( ) )
8071}
8172
73+ async fn static_fallback ( uri : Uri ) -> impl IntoResponse {
74+ let path = uri. path ( ) . split_at ( 1 ) . 1 ;
75+
76+ StaticAssets :: get ( path)
77+ . map ( |file| ( axum:: http:: StatusCode :: OK , [ ( axum:: http:: header:: CONTENT_TYPE , file. metadata . mimetype ( ) ) ] , file. data ) . into_response ( ) )
78+ . unwrap_or_else ( || {
79+ println ! ( "No route matched, returning 404!: {uri}." ) ;
80+ ( axum:: http:: StatusCode :: NOT_FOUND , "Not Found" . to_string ( ) ) . into_response ( )
81+ } )
82+ }
83+
8284fn prepare_request ( wasi_request : IncomingRequest ) -> Result < axum:: http:: Request < axum:: body:: Body > , String > {
8385 let mut tower_request = axum:: http:: Request :: builder ( )
8486 . uri ( wasi_request. path_with_query ( ) . ok_or ( "The incoming request from the Wasm runtime did not have a request path." ) ?)
0 commit comments