Skip to content

Commit

Permalink
Add ability to configure index file
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulSharer committed Jan 5, 2025
1 parent 0b09036 commit c27189c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions source/river/assets/test-config.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
1 change: 1 addition & 0 deletions source/river/src/config/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub struct PathControl {
#[derive(Debug, Clone)]
pub struct FileServerConfig {
pub(crate) name: String,
pub(crate) index_file: Vec<String>,
pub(crate) listeners: Vec<ListenerConfig>,
pub(crate) base_path: Option<PathBuf>,
}
Expand Down
9 changes: 9 additions & 0 deletions source/river/src/config/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down
2 changes: 1 addition & 1 deletion source/river/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c27189c

Please sign in to comment.