aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorjikstra <jikstra@disroot.org>2021-12-29 03:10:24 +0000
committerjikstra <jikstra@disroot.org>2021-12-29 03:10:24 +0000
commit2103ea0ed4df223b238dda96f142814692ed861d (patch)
treef958110b72123a8172ad93fc8df7bb534e862ecc /src/config.rs
parentMerge pull request #678 from svenstaro/dependabot/cargo/clap_generate-3.0.0-rc.9 (diff)
downloadminiserve-2103ea0ed4df223b238dda96f142814692ed861d.tar.gz
miniserve-2103ea0ed4df223b238dda96f142814692ed861d.zip
Implement --route-prefix to set specific route prefix
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs
index fda2f84..4b9d2dc 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -47,8 +47,8 @@ pub struct MiniserveConfig {
/// Show hidden files
pub show_hidden: bool,
- /// Enable random route generation
- pub random_route: Option<String>,
+ /// Route prefix
+ pub route_prefix: String,
/// Randomly generated favicon route
pub favicon_route: String,
@@ -131,10 +131,11 @@ impl MiniserveConfig {
]
};
- let random_route = if args.random_route {
- Some(nanoid::nanoid!(6, &ROUTE_ALPHABET))
- } else {
- None
+ let route_prefix = match (args.route_prefix, args.random_route) {
+ (Some(prefix), _) if prefix.starts_with('/') => prefix,
+ (Some(prefix), _) => format!("/{}", prefix),
+ (_, true) => format!("/{}", nanoid::nanoid!(6, &ROUTE_ALPHABET)),
+ _ => "".to_owned(),
};
// Generate some random routes for the favicon and css so that they are very unlikely to conflict with
@@ -185,7 +186,7 @@ impl MiniserveConfig {
path_explicitly_chosen,
no_symlinks: args.no_symlinks,
show_hidden: args.hidden,
- random_route,
+ route_prefix,
favicon_route,
css_route,
default_color_scheme,