[db] add --no-ui param

feat/vaults
Tomáš Mládek 2021-10-19 22:23:46 +02:00
parent fc07cd27c4
commit d07c9fd339
1 changed files with 15 additions and 4 deletions

View File

@ -49,6 +49,11 @@ fn main() -> Result<()> {
.long("no-browser") .long("no-browser")
.help("Do not open web browser with the UI."), .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(
Arg::with_name("NO_INITIAL_UPDATE") Arg::with_name("NO_INITIAL_UPDATE")
.long("no-initial-update") .long("no-initial-update")
@ -99,8 +104,9 @@ fn main() -> Result<()> {
}; };
// Start HTTP server // Start HTTP server
let ui_enabled = !matches.is_present("NO_UI");
HttpServer::new(move || { HttpServer::new(move || {
App::new() let app = App::new()
.data(state.clone()) .data(state.clone())
.wrap(middleware::Logger::default().exclude("/api/jobs")) .wrap(middleware::Logger::default().exclude("/api/jobs"))
.service(routes::get_raw) .service(routes::get_raw)
@ -113,14 +119,19 @@ fn main() -> Result<()> {
.service(routes::latest_files) .service(routes::latest_files)
.service(routes::get_file) .service(routes::get_file)
.service(routes::get_jobs) .service(routes::get_jobs)
.service(routes::get_info) .service(routes::get_info);
.service(
if ui_enabled {
app.service(
actix_files::Files::new( actix_files::Files::new(
"/", "/",
env::current_exe().unwrap().parent().unwrap().join("webui"), env::current_exe().unwrap().parent().unwrap().join("webui"),
) )
.index_file("index.html"), .index_file("index.html"),
) )
} else {
app
}
}) })
.bind(&bind)? .bind(&bind)?
.run(); .run();
@ -130,7 +141,7 @@ fn main() -> Result<()> {
actix::spawn(filesystem::rescan_vault(db_pool, vault_path, job_container)); 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())); let ui_result = webbrowser::open(&format!("http://localhost:{}", bind.port()));
if ui_result.is_err() { if ui_result.is_err() {
warn!("Could not open UI in browser!"); warn!("Could not open UI in browser!");