-
-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add abillity to set path prefix #579
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,9 +55,13 @@ pub struct CliArgs { | |
)] | ||
pub auth: Vec<auth::RequiredAuth>, | ||
|
||
/// Generate a random 6-hexdigit route | ||
#[structopt(long = "random-route")] | ||
pub random_route: bool, | ||
/// Use a specific path prefix | ||
#[structopt(long = "path-prefix")] | ||
pub path_prefix: Option<String>, | ||
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to rename to "route" IMO to avoid a breaking change and to be distinguished from filesystem path! |
||
|
||
/// Use a random path prefix | ||
#[structopt(long = "random-path-prefix", conflicts_with("path-prefix"))] | ||
pub random_path_prefix: bool, | ||
|
||
/// Do not follow symbolic links | ||
#[structopt(short = "P", long = "no-symlinks")] | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -109,8 +109,8 @@ fn build_unauthorized_response( | |||||||||
if log_error_chain { | ||||||||||
errors::log_error_chain(error.to_string()); | ||||||||||
} | ||||||||||
let return_path = match state.random_route { | ||||||||||
Some(ref random_route) => format!("/{}", random_route), | ||||||||||
let return_path = match state.path_prefix { | ||||||||||
Some(ref path_prefix) => format!("/{}", path_prefix), | ||||||||||
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
to better handle unexpected user input. |
||||||||||
None => "/".to_string(), | ||||||||||
}; | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,11 @@ pub struct MiniserveConfig { | |
/// Show hidden files | ||
pub show_hidden: bool, | ||
|
||
/// Enable random route generation | ||
pub random_route: Option<String>, | ||
/// Use a specific path prefix | ||
pub path_prefix: Option<String>, | ||
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer this to be just You may want to take a look at my previous PR 7ea3beb |
||
|
||
/// Use a random path prefix | ||
pub random_path_prefix: bool, | ||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused field. |
||
|
||
/// Randomly generated favicon route | ||
pub favicon_route: String, | ||
|
@@ -110,7 +113,9 @@ impl MiniserveConfig { | |
] | ||
}; | ||
|
||
let random_route = if args.random_route { | ||
let path_prefix = if let Some(path_prefix) = args.path_prefix { | ||
Some(path_prefix) | ||
} else if args.random_path_prefix { | ||
Some(nanoid::nanoid!(6, &ROUTE_ALPHABET)) | ||
} else { | ||
None | ||
|
@@ -159,7 +164,8 @@ impl MiniserveConfig { | |
path_explicitly_chosen, | ||
no_symlinks: args.no_symlinks, | ||
show_hidden: args.hidden, | ||
random_route, | ||
path_prefix, | ||
random_path_prefix: args.random_path_prefix, | ||
favicon_route, | ||
css_route, | ||
default_color_scheme, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the whitespaces here? Thanks for updating the README but let's not introduce unnecessary whitespaces.