Skip to content

Commit 950c4db

Browse files
committed
Update tree usage
1 parent 2b051b4 commit 950c4db

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

engine/src/server/mod.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ async fn resolve_http(request: &Request, state: Data<&State>) -> impl IntoRespon
105105
let state_for_file = state_ref.clone();
106106
let deployment_str = deployment_id.to_string();
107107
let state_for_file_str = state_for_file.clone();
108+
let path_str = path.clone();
108109
let maybe_file = state_ref
109110
.cache
110111
.file_entry
111112
.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)
113114
.await
114115
.ok()
115116
})
@@ -118,6 +119,26 @@ async fn resolve_http(request: &Request, state: Data<&State>) -> impl IntoRespon
118119
return serve_deployment_file(deployment_file, last_modified, cid, state_ref).await;
119120
}
120121

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+
121142
// 3) SPA fallback -> index.html
122143
let spa_key = format!("{}:index.html", deployment_id);
123144
let maybe_spa = state_ref
@@ -199,7 +220,8 @@ async fn serve_deployment_file(
199220
.status(StatusCode::OK)
200221
.header("content-type", mime.clone())
201222
.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");
203225
// optionally include IPFS path
204226
if let Some(cid_val) = &cid {
205227
let ipfs_path = format!(
@@ -221,7 +243,8 @@ async fn serve_deployment_file(
221243
.status(StatusCode::OK)
222244
.header("content-type", mime.clone())
223245
.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");
225248
if let Some(cid_val) = &cid {
226249
let ipfs_path = format!(
227250
"/ipfs/{}/{}",
@@ -251,7 +274,8 @@ async fn serve_deployment_file(
251274
.status(StatusCode::OK)
252275
.header("content-type", mime)
253276
.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");
255279
if let Some(cid_val) = &cid {
256280
let ipfs_path = format!(
257281
"/ipfs/{}/{}",

0 commit comments

Comments
 (0)