From c27189cafaf62cc2dc3fc8999d00e6692c1b9ddc Mon Sep 17 00:00:00 2001 From: Yaroslav Shmelev Date: Sun, 5 Jan 2025 14:08:54 +0300 Subject: [PATCH] Add ability to configure index file --- source/river/assets/test-config.kdl | 4 ++++ source/river/src/config/internal.rs | 1 + source/river/src/config/kdl/mod.rs | 9 +++++++++ source/river/src/files.rs | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/river/assets/test-config.kdl b/source/river/assets/test-config.kdl index d6e1e2c..81f8674 100644 --- a/source/river/assets/test-config.kdl +++ b/source/river/assets/test-config.kdl @@ -129,6 +129,10 @@ services { // // All files within the root will be available base-path "." + // Redirect to an index file on URI like "/" GET, can include multiple options + // + // This is optional. + index-file "index.html" } } } diff --git a/source/river/src/config/internal.rs b/source/river/src/config/internal.rs index db96c94..65124be 100644 --- a/source/river/src/config/internal.rs +++ b/source/river/src/config/internal.rs @@ -135,6 +135,7 @@ pub struct PathControl { #[derive(Debug, Clone)] pub struct FileServerConfig { pub(crate) name: String, + pub(crate) index_file: Vec, pub(crate) listeners: Vec, pub(crate) base_path: Option, } diff --git a/source/river/src/config/kdl/mod.rs b/source/river/src/config/kdl/mod.rs index 68b8ea2..becf8be 100644 --- a/source/river/src/config/kdl/mod.rs +++ b/source/river/src/config/kdl/mod.rs @@ -222,10 +222,19 @@ fn extract_file_server( None }; + // Index File + // + let index_file = if let Some((ifnode, ifargs)) = map.get("index-file") { + ifargs.iter().filter_map(|arg| arg.value().as_string().map(ToOwned::to_owned)).collect() + } else { + vec![] + }; + Ok(FileServerConfig { name: name.to_string(), listeners: list_cfgs, base_path, + index_file }) } diff --git a/source/river/src/files.rs b/source/river/src/files.rs index 689df92..32d6e54 100644 --- a/source/river/src/files.rs +++ b/source/river/src/files.rs @@ -18,7 +18,7 @@ pub fn river_file_server( let fsconf = StaticFilesConf { root: conf.base_path, canonicalize_uri: true, - index_file: Vec::new().into(), + index_file: conf.index_file.into(), page_404: None, precompressed: Vec::new().into(), ..Default::default()