From c10bc016ef651b390c3cccc53bad6c45ec6cf765 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Fri, 6 Sep 2019 12:49:08 -0400 Subject: add a default index serving option --- src/args.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index 47f4d1f..b4b50e2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -27,6 +27,10 @@ struct CLIArgs { #[structopt(name = "PATH", parse(from_os_str))] path: Option, + /// serve index.* files by default + #[structopt(short = "d", long)] + default_index: bool, + /// Port to use #[structopt(short = "p", long = "port", default_value = "8080")] port: u16, -- cgit v1.2.3 From d68a874d18e79eecb7f6a4ba941a3494e408322a Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Sat, 7 Sep 2019 20:50:15 -0400 Subject: wire up arguments, index.html serving still broken --- src/args.rs | 1 + src/main.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index b4b50e2..6a3a4a5 100644 --- a/src/args.rs +++ b/src/args.rs @@ -166,6 +166,7 @@ pub fn parse_args() -> crate::MiniserveConfig { no_symlinks: args.no_symlinks, random_route, default_color_scheme, + default_index: args.default_index, overwrite_files: args.overwrite_files, file_upload: args.file_upload, } diff --git a/src/main.rs b/src/main.rs index dc98df0..46c38d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use simplelog::{Config, LevelFilter, TermLogger, TerminalMode}; use std::io::{self, Write}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::thread; +use std::path::PathBuf; use std::time::Duration; use yansi::{Color, Paint}; @@ -52,6 +53,9 @@ pub struct MiniserveConfig { /// Default color scheme pub default_color_scheme: themes::ColorScheme, + /// Serve index.* files by default + pub default_index: bool, + /// Enable file upload pub file_upload: bool, @@ -234,6 +238,13 @@ fn configure_app(app: App) -> App { }; if path.is_file() { None + } else if app.state().default_index == true { + let mut index_path = PathBuf::from(path); + index_path.push("index.html"); + Some( + fs::StaticFiles::new(index_path) + .expect("Failed to setup static file handler") + ) } else { let u_r = upload_route.clone(); Some( -- cgit v1.2.3 From a861bd22855f83163fa00f59de04b11628c9e7a5 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Mon, 9 Sep 2019 12:20:42 -0400 Subject: use actix-web method for static index --- src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 46c38d1..f2dd351 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ use simplelog::{Config, LevelFilter, TermLogger, TerminalMode}; use std::io::{self, Write}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::thread; -use std::path::PathBuf; use std::time::Duration; use yansi::{Color, Paint}; @@ -239,11 +238,10 @@ fn configure_app(app: App) -> App { if path.is_file() { None } else if app.state().default_index == true { - let mut index_path = PathBuf::from(path); - index_path.push("index.html"); Some( - fs::StaticFiles::new(index_path) + fs::StaticFiles::new(path) .expect("Failed to setup static file handler") + .index_file("index.html") ) } else { let u_r = upload_route.clone(); -- cgit v1.2.3 From b3f170e7edf77e6a37f11af8701d427a9b2fe204 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 12 Sep 2019 19:57:21 -0400 Subject: change to path option for configurability --- src/args.rs | 8 ++++---- src/main.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index 6a3a4a5..d31cb26 100644 --- a/src/args.rs +++ b/src/args.rs @@ -27,9 +27,9 @@ struct CLIArgs { #[structopt(name = "PATH", parse(from_os_str))] path: Option, - /// serve index.* files by default - #[structopt(short = "d", long)] - default_index: bool, + /// name of an index files to serve by default + #[structopt(long, parse(from_os_str), name="index_file")] + index: Option, /// Port to use #[structopt(short = "p", long = "port", default_value = "8080")] @@ -166,7 +166,7 @@ pub fn parse_args() -> crate::MiniserveConfig { no_symlinks: args.no_symlinks, random_route, default_color_scheme, - default_index: args.default_index, + index: args.index, overwrite_files: args.overwrite_files, file_upload: args.file_upload, } diff --git a/src/main.rs b/src/main.rs index f2dd351..5db9b31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,8 +52,8 @@ pub struct MiniserveConfig { /// Default color scheme pub default_color_scheme: themes::ColorScheme, - /// Serve index.* files by default - pub default_index: bool, + /// name of an index files to serve by default + pub index: Option, /// Enable file upload pub file_upload: bool, @@ -237,11 +237,11 @@ fn configure_app(app: App) -> App { }; if path.is_file() { None - } else if app.state().default_index == true { + } else if let Some(index_file) = &app.state().index { Some( fs::StaticFiles::new(path) .expect("Failed to setup static file handler") - .index_file("index.html") + .index_file(index_file.to_string_lossy()) ) } else { let u_r = upload_route.clone(); -- cgit v1.2.3 From cd03f984bacbcacc57d5ce07c13bc401b48c09f9 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 12 Sep 2019 20:14:07 -0400 Subject: warn user if provided index file is not found --- src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5db9b31..d5055b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,6 +122,14 @@ fn run() -> Result<(), ContextualError> { let canon_path = miniserve_config.path.canonicalize().map_err(|e| { ContextualError::IOError("Failed to resolve path to be served".to_string(), e) })?; + + if let Some(index_path) = &miniserve_config.index { + let has_index: std::path::PathBuf = [&canon_path, index_path].iter().collect(); + if !has_index.exists() { + + println!("{warning} The provided index file could not be found.", warning=Color::RGB(255, 192, 0).paint("Notice:").bold()); + } + } let path_string = canon_path.to_string_lossy(); println!( -- cgit v1.2.3 From f92fb9bd401198dbab27edf3bbd2435a104a1c72 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Sat, 14 Sep 2019 12:45:22 -0400 Subject: fix typo --- src/args.rs | 2 +- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index d31cb26..0d4e3ce 100644 --- a/src/args.rs +++ b/src/args.rs @@ -27,7 +27,7 @@ struct CLIArgs { #[structopt(name = "PATH", parse(from_os_str))] path: Option, - /// name of an index files to serve by default + /// name of an index file to serve by default #[structopt(long, parse(from_os_str), name="index_file")] index: Option, diff --git a/src/main.rs b/src/main.rs index d5055b9..3bb521c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ pub struct MiniserveConfig { /// Default color scheme pub default_color_scheme: themes::ColorScheme, - /// name of an index files to serve by default + /// name of an index file to serve by default pub index: Option, /// Enable file upload -- cgit v1.2.3 From bbe3cb3975f011b40d94c155bc0e80e0bd6ce391 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Mon, 3 Feb 2020 15:29:53 -0500 Subject: add Lucretiel's documentation suggestion --- src/args.rs | 5 ++++- src/main.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index ad5f1d6..95ddaf7 100644 --- a/src/args.rs +++ b/src/args.rs @@ -27,7 +27,10 @@ struct CLIArgs { #[structopt(name = "PATH", parse(from_os_str))] path: Option, - /// name of an index file to serve by default + /// The name of a directory index file to serve, like "index.html" + /// + /// Normally, when miniserve serves a directory, it creates a listing for that directory. + /// However, if a directory contains this file, miniserve will serve that file instead. #[structopt(long, parse(from_os_str), name="index_file")] index: Option, diff --git a/src/main.rs b/src/main.rs index c31341e..11cf5c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,10 @@ pub struct MiniserveConfig { /// Default color scheme pub default_color_scheme: themes::ColorScheme, - /// name of an index file to serve by default + /// The name of a directory index file to serve, like "index.html" + /// + /// Normally, when miniserve serves a directory, it creates a listing for that directory. + /// However, if a directory contains this file, miniserve will serve that file instead. pub index: Option, /// Enable file upload -- cgit v1.2.3