From 852d64b38d2ab9d1179e0f9952a76868ac4f34fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 28 Jan 2024 14:35:17 +0100 Subject: [PATCH] fix(cli): serving web ui in Docker/AppImage --- Cargo.lock | 7 ------- cli/Cargo.toml | 1 - cli/src/common.rs | 24 ++++++++++++++---------- cli/src/main.rs | 4 ++-- cli/src/serve.rs | 4 ++-- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 300ba10..3715c10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -819,12 +819,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" -[[package]] -name = "constcat" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5cd0c57ef83705837b1cb872c973eff82b070846d3e23668322b2c0f8246d0" - [[package]] name = "convert_case" version = "0.4.0" @@ -3335,7 +3329,6 @@ dependencies = [ "bytes", "chrono", "clap", - "constcat", "diesel", "diesel_migrations", "filebuffer", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d521223..4c2cbbd 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -90,7 +90,6 @@ url = "2" bytes = "1.4.0" signal-hook = "0.3.15" actix-web-lab = { version = "0.20.2", features = ["spa"] } -constcat = "0.4.1" [build-dependencies] shadow-rs = { version = "0.23", default-features = false } diff --git a/cli/src/common.rs b/cli/src/common.rs index e30efea..f95292a 100644 --- a/cli/src/common.rs +++ b/cli/src/common.rs @@ -1,19 +1,23 @@ -use constcat::concat; +use std::env::current_exe; +use std::path::PathBuf; use lazy_static::lazy_static; -use shadow_rs::shadow; +use shadow_rs::{is_debug, shadow}; shadow!(build); -#[cfg(not(debug_assertions))] -pub const RESOURCE_PATH: &str = "../share/upend"; - -#[cfg(debug_assertions)] -pub const RESOURCE_PATH: &str = "./tmp/resources"; - -pub const WEBUI_PATH: &str = concat!(RESOURCE_PATH, "/webui"); - lazy_static! { + pub static ref RESOURCE_PATH: PathBuf = if is_debug() { + let project_root = build::CARGO_MANIFEST_DIR.parse::().unwrap(); + project_root.join("./tmp/resources") + } else { + current_exe() + .unwrap() + .parent() + .unwrap() + .join("../share/upend") + }; + pub static ref WEBUI_PATH: PathBuf = RESOURCE_PATH.join("webui"); static ref APP_USER_AGENT: String = format!("upend / {}", build::PKG_VERSION); pub static ref REQWEST_CLIENT: reqwest::blocking::Client = reqwest::blocking::Client::builder() .user_agent(APP_USER_AGENT.as_str()) diff --git a/cli/src/main.rs b/cli/src/main.rs index df39483..6f41d55 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -345,11 +345,11 @@ async fn main() -> Result<()> { let webui_enabled = if args.no_ui { false } else { - let exists = Path::new(WEBUI_PATH).exists(); + let exists = WEBUI_PATH.exists(); if !exists { warn!( "Couldn't locate Web UI directory ({:?}), disabling...", - WEBUI_PATH + WEBUI_PATH.to_owned() ); } exists diff --git a/cli/src/serve.rs b/cli/src/serve.rs index 9b95c3d..96dccde 100644 --- a/cli/src/serve.rs +++ b/cli/src/serve.rs @@ -71,8 +71,8 @@ where if ui_enabled { return app.service( spa() - .index_file(crate::common::WEBUI_PATH.to_owned() + "/index.html") - .static_resources_location(crate::common::WEBUI_PATH) + .index_file(crate::common::WEBUI_PATH.to_str().unwrap().to_owned() + "/index.html") + .static_resources_location(crate::common::WEBUI_PATH.to_str().unwrap()) .finish(), ); }