Skip to content

Commit fa2ebf0

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

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-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/config/kdl/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ fn load_test() {
168168
},
169169
],
170170
base_path: Some(".".into()),
171+
index_file: vec!["index.html".to_string()],
171172
}],
172173
daemonize: false,
173174
pid_file: Some("/tmp/river.pidfile".into()),
@@ -209,10 +210,12 @@ fn load_test() {
209210
name,
210211
listeners,
211212
base_path,
213+
index_file,
212214
} = afs;
213215
assert_eq!(*name, efs.name);
214216
assert_eq!(*listeners, efs.listeners);
215217
assert_eq!(*base_path, efs.base_path);
218+
assert_eq!(*index_file, efs.index_file);
216219
}
217220
}
218221

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)