Skip to content

Commit 2cc07a3

Browse files
committed
Add ability to configure index file
1 parent 0b09036 commit 2cc07a3

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

source/river/assets/test-config.kdl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ services {
129129
//
130130
// All files within the root will be available
131131
base-path "."
132+
// Redirect to an index file on URI like "/" GET, can include multiple options
133+
//
134+
// This is optional.
135+
index-file "index.html"
132136
}
133137
}
134138
}

source/river/src/config/internal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pub struct PathControl {
135135
#[derive(Debug, Clone)]
136136
pub struct FileServerConfig {
137137
pub(crate) name: String,
138+
pub(crate) index_file: Vec<String>,
138139
pub(crate) listeners: Vec<ListenerConfig>,
139140
pub(crate) base_path: Option<PathBuf>,
140141
}

source/river/src/config/kdl/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,22 @@ fn extract_file_server(
222222
None
223223
};
224224

225+
// Index File
226+
//
227+
let index_file = if let Some((ifnode, ifargs)) = map.get("index-file") {
228+
ifargs
229+
.iter()
230+
.filter_map(|arg| arg.value().as_string().map(ToOwned::to_owned))
231+
.collect()
232+
} else {
233+
vec![]
234+
};
235+
225236
Ok(FileServerConfig {
226237
name: name.to_string(),
227238
listeners: list_cfgs,
228239
base_path,
240+
index_file,
229241
})
230242
}
231243

source/river/src/files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn river_file_server(
1818
let fsconf = StaticFilesConf {
1919
root: conf.base_path,
2020
canonicalize_uri: true,
21-
index_file: Vec::new().into(),
21+
index_file: conf.index_file.into(),
2222
page_404: None,
2323
precompressed: Vec::new().into(),
2424
..Default::default()

0 commit comments

Comments
 (0)