@@ -105,11 +105,12 @@ async fn resolve_http(request: &Request, state: Data<&State>) -> impl IntoRespon
105
105
let state_for_file = state_ref. clone ( ) ;
106
106
let deployment_str = deployment_id. to_string ( ) ;
107
107
let state_for_file_str = state_for_file. clone ( ) ;
108
+ let path_str = path. clone ( ) ;
108
109
let maybe_file = state_ref
109
110
. cache
110
111
. file_entry
111
112
. get_with ( entry_key. clone ( ) , async move {
112
- DeploymentFile :: get_file_by_path ( & state_for_file_str. database , & deployment_str, & path )
113
+ DeploymentFile :: get_file_by_path ( & state_for_file_str. database , & deployment_str, & path_str )
113
114
. await
114
115
. ok ( )
115
116
} )
@@ -118,6 +119,26 @@ async fn resolve_http(request: &Request, state: Data<&State>) -> impl IntoRespon
118
119
return serve_deployment_file ( deployment_file, last_modified, cid, state_ref) . await ;
119
120
}
120
121
122
+ // 2b) if path is a directory, try <path>/index.html
123
+ if !path. is_empty ( ) {
124
+ let index_path = format ! ( "{}/index.html" , path) ;
125
+ let index_key = format ! ( "{}:{}" , deployment_id, index_path) ;
126
+ let state_for_index = state_ref. clone ( ) ;
127
+ let deployment_id_index = deployment_id. clone ( ) ;
128
+ let maybe_index = state_ref
129
+ . cache
130
+ . file_entry
131
+ . get_with ( index_key. clone ( ) , async move {
132
+ DeploymentFile :: get_file_by_path ( & state_for_index. database , & deployment_id_index, & index_path)
133
+ . await
134
+ . ok ( )
135
+ } )
136
+ . await ;
137
+ if let Some ( deployment_file) = maybe_index {
138
+ return serve_deployment_file ( deployment_file, last_modified, cid, state_ref) . await ;
139
+ }
140
+ }
141
+
121
142
// 3) SPA fallback -> index.html
122
143
let spa_key = format ! ( "{}:index.html" , deployment_id) ;
123
144
let maybe_spa = state_ref
@@ -199,7 +220,8 @@ async fn serve_deployment_file(
199
220
. status ( StatusCode :: OK )
200
221
. header ( "content-type" , mime. clone ( ) )
201
222
. header ( "ETag" , format ! ( "\" {}\" " , file_key) )
202
- . header ( "Last-Modified" , last_modified. to_rfc2822 ( ) ) ;
223
+ . header ( "Last-Modified" , last_modified. to_rfc2822 ( ) )
224
+ . header ( "Cache-Control" , "max-age=300" ) ;
203
225
// optionally include IPFS path
204
226
if let Some ( cid_val) = & cid {
205
227
let ipfs_path = format ! (
@@ -221,7 +243,8 @@ async fn serve_deployment_file(
221
243
. status ( StatusCode :: OK )
222
244
. header ( "content-type" , mime. clone ( ) )
223
245
. header ( "ETag" , format ! ( "\" {}\" " , file_key) )
224
- . header ( "Last-Modified" , last_modified. to_rfc2822 ( ) ) ;
246
+ . header ( "Last-Modified" , last_modified. to_rfc2822 ( ) )
247
+ . header ( "Cache-Control" , "max-age=300" ) ;
225
248
if let Some ( cid_val) = & cid {
226
249
let ipfs_path = format ! (
227
250
"/ipfs/{}/{}" ,
@@ -251,7 +274,8 @@ async fn serve_deployment_file(
251
274
. status ( StatusCode :: OK )
252
275
. header ( "content-type" , mime)
253
276
. header ( "ETag" , format ! ( "\" {}\" " , file_key) )
254
- . header ( "Last-Modified" , last_modified. to_rfc2822 ( ) ) ;
277
+ . header ( "Last-Modified" , last_modified. to_rfc2822 ( ) )
278
+ . header ( "Cache-Control" , "max-age=300" ) ;
255
279
if let Some ( cid_val) = & cid {
256
280
let ipfs_path = format ! (
257
281
"/ipfs/{}/{}" ,
0 commit comments