From 2103ea0ed4df223b238dda96f142814692ed861d Mon Sep 17 00:00:00 2001 From: jikstra Date: Wed, 29 Dec 2021 04:10:24 +0100 Subject: Implement --route-prefix to set specific route prefix --- src/config.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/config.rs') 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, + /// 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, -- cgit v1.2.3 From d64b2544e53a474f93e4ad3d3ff87639930b906b Mon Sep 17 00:00:00 2001 From: Jikstra <34889164+Jikstra@users.noreply.github.com> Date: Mon, 3 Jan 2022 20:14:04 +0100 Subject: Update src/config.rs Co-authored-by: Ali MJ Al-Nasrawy --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 4b9d2dc..94e232f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -133,7 +133,7 @@ impl MiniserveConfig { let route_prefix = match (args.route_prefix, args.random_route) { (Some(prefix), _) if prefix.starts_with('/') => prefix, - (Some(prefix), _) => format!("/{}", prefix), + (Some(prefix), _) => format!("/{}", prefix.trim_matches('/')), (_, true) => format!("/{}", nanoid::nanoid!(6, &ROUTE_ALPHABET)), _ => "".to_owned(), }; -- cgit v1.2.3 From 48f192e3499ee9609660a3e8bfcba22cc4a93ee8 Mon Sep 17 00:00:00 2001 From: Jikstra <34889164+Jikstra@users.noreply.github.com> Date: Tue, 4 Jan 2022 18:08:03 +0100 Subject: Apply alimjays suggestion Co-authored-by: Ali MJ Al-Nasrawy --- src/config.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 94e232f..b163e96 100644 --- a/src/config.rs +++ b/src/config.rs @@ -132,7 +132,6 @@ impl MiniserveConfig { }; let route_prefix = match (args.route_prefix, args.random_route) { - (Some(prefix), _) if prefix.starts_with('/') => prefix, (Some(prefix), _) => format!("/{}", prefix.trim_matches('/')), (_, true) => format!("/{}", nanoid::nanoid!(6, &ROUTE_ALPHABET)), _ => "".to_owned(), -- cgit v1.2.3 From 0e6adbb3b53147f2e78a907909f6c470190ebaf3 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Sun, 6 Feb 2022 14:48:33 +0300 Subject: Fix route_prefix for css and favicon --- src/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index ae260af..73fcec2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,7 +47,7 @@ pub struct MiniserveConfig { /// Show hidden files pub show_hidden: bool, - /// Route prefix + /// Route prefix; Either empty or prefixed with slash pub route_prefix: String, /// Randomly generated favicon route @@ -139,8 +139,8 @@ impl MiniserveConfig { // Generate some random routes for the favicon and css so that they are very unlikely to conflict with // real files. - let favicon_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); - let css_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); + let favicon_route = format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)); + let css_route = format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)); let default_color_scheme = args.color_scheme; let default_color_scheme_dark = args.color_scheme_dark; -- cgit v1.2.3