@@ -77,27 +77,30 @@ pub async fn serve(
77
77
static_prefix = String :: from ( "/" ) ;
78
78
}
79
79
80
- app = app. service (
81
- Files :: new ( & static_prefix, root_path. join ( "public" ) )
82
- . index_file ( "index.html" )
83
- // This handler check if there's an HTML file in the public folder that
84
- // can reply to the given request. For example, if someone request /about,
85
- // this handler will look for a /public/about.html file.
86
- . default_handler ( fn_service ( |req : ServiceRequest | async {
87
- let ( req, _) = req. into_parts ( ) ;
80
+ let public_dir = root_path. join ( "public" ) ;
81
+ if public_dir. exists ( ) {
82
+ app = app. service (
83
+ Files :: new ( & static_prefix, public_dir)
84
+ . index_file ( "index.html" )
85
+ // This handler check if there's an HTML file in the public folder that
86
+ // can reply to the given request. For example, if someone request /about,
87
+ // this handler will look for a /public/about.html file.
88
+ . default_handler ( fn_service ( |req : ServiceRequest | async {
89
+ let ( req, _) = req. into_parts ( ) ;
88
90
89
- match handle_assets ( & req) . await {
90
- Ok ( existing_file) => {
91
- let res = existing_file. into_response ( & req) ;
92
- Ok ( ServiceResponse :: new ( req, res) )
91
+ match handle_assets ( & req) . await {
92
+ Ok ( existing_file) => {
93
+ let res = existing_file. into_response ( & req) ;
94
+ Ok ( ServiceResponse :: new ( req, res) )
95
+ }
96
+ Err ( _) => {
97
+ let res = handle_not_found ( & req) . await ;
98
+ Ok ( ServiceResponse :: new ( req, res) )
99
+ }
93
100
}
94
- Err ( _) => {
95
- let res = handle_not_found ( & req) . await ;
96
- Ok ( ServiceResponse :: new ( req, res) )
97
- }
98
- }
99
- } ) ) ,
100
- ) ;
101
+ } ) ) ,
102
+ ) ;
103
+ }
101
104
102
105
app
103
106
} )
0 commit comments