Skip to content

Commit c27189c

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

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,19 @@ 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.iter().filter_map(|arg| arg.value().as_string().map(ToOwned::to_owned)).collect()
229+
} else {
230+
vec![]
231+
};
232+
225233
Ok(FileServerConfig {
226234
name: name.to_string(),
227235
listeners: list_cfgs,
228236
base_path,
237+
index_file
229238
})
230239
}
231240

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)