@@ -129,27 +129,30 @@ pub async fn serve(serve_options: ServeOptions) -> Result<Server> {
129
129
static_prefix = String :: from ( "/" ) ;
130
130
}
131
131
132
- app = app. service (
133
- Files :: new ( & static_prefix, app_data. root_path . join ( "public" ) )
134
- . index_file ( "index.html" )
135
- // This handler check if there's an HTML file in the public folder that
136
- // can reply to the given request. For example, if someone request /about,
137
- // this handler will look for a /public/about.html file.
138
- . default_handler ( fn_service ( |req : ServiceRequest | async {
139
- let ( req, _) = req. into_parts ( ) ;
140
-
141
- match handle_assets ( & req) . await {
142
- Ok ( existing_file) => {
143
- let res = existing_file. into_response ( & req) ;
144
- Ok ( ServiceResponse :: new ( req, res) )
132
+ let public_dir = app_data. root_path . join ( "public" ) ;
133
+ if public_dir. exists ( ) {
134
+ app = app. service (
135
+ Files :: new ( & static_prefix, public_dir)
136
+ . index_file ( "index.html" )
137
+ // This handler check if there's an HTML file in the public folder that
138
+ // can reply to the given request. For example, if someone request /about,
139
+ // this handler will look for a /public/about.html file.
140
+ . default_handler ( fn_service ( |req : ServiceRequest | async {
141
+ let ( req, _) = req. into_parts ( ) ;
142
+
143
+ match handle_assets ( & req) . await {
144
+ Ok ( existing_file) => {
145
+ let res = existing_file. into_response ( & req) ;
146
+ Ok ( ServiceResponse :: new ( req, res) )
147
+ }
148
+ Err ( _) => {
149
+ let res = handle_not_found ( & req) . await ;
150
+ Ok ( ServiceResponse :: new ( req, res) )
151
+ }
145
152
}
146
- Err ( _) => {
147
- let res = handle_not_found ( & req) . await ;
148
- Ok ( ServiceResponse :: new ( req, res) )
149
- }
150
- }
151
- } ) ) ,
152
- ) ;
153
+ } ) ) ,
154
+ ) ;
155
+ }
153
156
154
157
app
155
158
} )
0 commit comments