From d07c9fd33908259fda2c24a126fbadf6593361e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Tue, 19 Oct 2021 22:23:46 +0200 Subject: [PATCH] [db] add --no-ui param --- src/main.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bff357b..c045199 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,11 @@ fn main() -> Result<()> { .long("no-browser") .help("Do not open web browser with the UI."), ) + .arg( + Arg::with_name("NO_UI") + .long("no-ui") + .help("Do not serve the web UI."), + ) .arg( Arg::with_name("NO_INITIAL_UPDATE") .long("no-initial-update") @@ -99,8 +104,9 @@ fn main() -> Result<()> { }; // Start HTTP server + let ui_enabled = !matches.is_present("NO_UI"); HttpServer::new(move || { - App::new() + let app = App::new() .data(state.clone()) .wrap(middleware::Logger::default().exclude("/api/jobs")) .service(routes::get_raw) @@ -113,14 +119,19 @@ fn main() -> Result<()> { .service(routes::latest_files) .service(routes::get_file) .service(routes::get_jobs) - .service(routes::get_info) - .service( + .service(routes::get_info); + + if ui_enabled { + app.service( actix_files::Files::new( "/", env::current_exe().unwrap().parent().unwrap().join("webui"), ) .index_file("index.html"), ) + } else { + app + } }) .bind(&bind)? .run(); @@ -130,7 +141,7 @@ fn main() -> Result<()> { actix::spawn(filesystem::rescan_vault(db_pool, vault_path, job_container)); } - if !matches.is_present("NO_BROWSER") { + if !matches.is_present("NO_BROWSER") && ui_enabled { let ui_result = webbrowser::open(&format!("http://localhost:{}", bind.port())); if ui_result.is_err() { warn!("Could not open UI in browser!");