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 8, 2025
1 parent 0b09036 commit fa2ebf0
Show file tree
Hide file tree
Showing 5 changed files with 21 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
12 changes: 12 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,22 @@ 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
3 changes: 3 additions & 0 deletions source/river/src/config/kdl/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fn load_test() {
},
],
base_path: Some(".".into()),
index_file: vec!["index.html".to_string()],
}],
daemonize: false,
pid_file: Some("/tmp/river.pidfile".into()),
Expand Down Expand Up @@ -209,10 +210,12 @@ fn load_test() {
name,
listeners,
base_path,
index_file,
} = afs;
assert_eq!(*name, efs.name);
assert_eq!(*listeners, efs.listeners);
assert_eq!(*base_path, efs.base_path);
assert_eq!(*index_file, efs.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 fa2ebf0

Please sign in to comment.