aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs
index eb159a2..205fac5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,10 +9,10 @@ use actix_files::NamedFile;
use actix_web::web;
use actix_web::{http::header::ContentType, Responder};
use actix_web::{middleware, App, HttpRequest, HttpResponse};
-use anyhow::{bail, Result};
-use clap::{crate_version, Clap, IntoApp};
-use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh};
-use clap_generate::{generate, Shell};
+use actix_web_httpauth::middleware::HttpAuthentication;
+use anyhow::Result;
+use clap::{crate_version, IntoApp, Parser};
+use clap_generate::generate;
use log::{error, warn};
use qrcodegen::{QrCode, QrCodeEcc};
use yansi::{Color, Paint};
@@ -35,18 +35,8 @@ fn main() -> Result<()> {
if let Some(shell) = args.print_completions {
let mut clap_app = args::CliArgs::into_app();
- match shell {
- Shell::Bash => generate::<Bash, _>(&mut clap_app, "miniserve", &mut std::io::stdout()),
- Shell::Elvish => {
- generate::<Elvish, _>(&mut clap_app, "miniserve", &mut std::io::stdout())
- }
- Shell::Fish => generate::<Fish, _>(&mut clap_app, "miniserve", &mut std::io::stdout()),
- Shell::PowerShell => {
- generate::<PowerShell, _>(&mut clap_app, "miniserve", &mut std::io::stdout())
- }
- Shell::Zsh => generate::<Zsh, _>(&mut clap_app, "miniserve", &mut std::io::stdout()),
- _ => bail!("Invalid shell provided!"),
- }
+ let app_name = clap_app.get_name().to_string();
+ generate(shell, &mut clap_app, app_name, &mut io::stdout());
return Ok(());
}
@@ -207,11 +197,10 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.route(&format!("/{}", inside_config.css_route), web::get().to(css))
.service(
web::scope(inside_config.random_route.as_deref().unwrap_or(""))
- // we should use `actix_web_httpauth::middleware::HttpAuthentication`
- // but it is unfortuantrly broken
- // see: https://github.com/actix/actix-extras/issues/127
- // TODO replace this when fixed upstream
- .wrap_fn(auth::auth_middleware)
+ .wrap(middleware::Condition::new(
+ !inside_config.auth.is_empty(),
+ HttpAuthentication::basic(auth::handle_auth),
+ ))
.configure(|c| configure_app(c, &inside_config)),
)
.default_service(web::get().to(error_404))