@@ -3,6 +3,7 @@ use axum::{
33 http:: StatusCode ,
44 response:: { Html , IntoResponse } ,
55} ;
6+ use tower_http:: services:: ServeDir ;
67
78use crate :: backend:: api:: api_router;
89use crate :: backend:: user:: { basic_auth, basic_auth_if_public} ;
@@ -14,6 +15,8 @@ pub fn create_router() -> Router {
1415 . nest ( "/api" , api_router ( ) )
1516 // Admin routes
1617 . nest ( "/admin" , admin_router ( ) )
18+ // Static files from alu-panel/dist
19+ . merge ( static_router ( ) )
1720 // Fallback for web UI
1821 // todo: bundle into executable
1922 . fallback ( || async {
@@ -25,6 +28,25 @@ pub fn create_router() -> Router {
2528 . layer ( axum:: middleware:: from_fn ( basic_auth_if_public) )
2629}
2730
31+ pub fn static_router ( ) -> Router {
32+ Router :: new ( )
33+ // Static files from alu-panel/dist
34+ . nest_service ( "/static" , ServeDir :: new ( "alu-panel/dist/static" ) )
35+ . route (
36+ "/favicon.ico" ,
37+ axum:: routing:: get ( || async {
38+ Html ( std:: fs:: read_to_string ( "alu-panel/dist/favicon.ico" ) . unwrap ( ) )
39+ } ) ,
40+ )
41+ // Fallback for web UI
42+ . fallback ( || async {
43+ match std:: fs:: read_to_string ( "alu-panel/dist/index.html" ) {
44+ Ok ( contents) => Html ( contents) . into_response ( ) ,
45+ Err ( _) => StatusCode :: NOT_FOUND . into_response ( ) ,
46+ }
47+ } )
48+ }
49+
2850/// Create the admin router with authentication
2951pub fn admin_router ( ) -> Router {
3052 Router :: new ( )
0 commit comments