static dirs are handled for both debug and release
parent
48837712de
commit
b80d547689
|
@ -1 +1,18 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
|
||||
pub fn get_static_dir<S: AsRef<str>>(dir: S) -> Result<std::path::PathBuf> {
|
||||
let cwd = std::env::current_exe()?.parent().unwrap().to_path_buf();
|
||||
let base_path = if PROFILE == "debug" {
|
||||
cwd.join("../../tmp/static")
|
||||
} else {
|
||||
cwd
|
||||
};
|
||||
let result = base_path.join(dir.as_ref());
|
||||
if result.exists() {
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(anyhow!("Path {result:?} doesn't exist."))
|
||||
}
|
||||
}
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -5,7 +5,6 @@ extern crate diesel_migrations;
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -15,7 +14,10 @@ use clap::{App as ClapApp, Arg};
|
|||
use log::{debug, info, warn};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::{common::PKG_VERSION, database::UpEndDatabase};
|
||||
use crate::{
|
||||
common::{get_static_dir, PKG_VERSION},
|
||||
database::UpEndDatabase,
|
||||
};
|
||||
|
||||
mod addressing;
|
||||
mod common;
|
||||
|
@ -101,12 +103,15 @@ fn main() -> Result<()> {
|
|||
|
||||
let upend = Arc::new(open_result.db);
|
||||
|
||||
let ui_path = env::current_exe().unwrap().parent().unwrap().join("webui");
|
||||
if !ui_path.exists() {
|
||||
warn!("No Web UI directory present ({:?}), disabling...", ui_path);
|
||||
let ui_path = get_static_dir("webui");
|
||||
if ui_path.is_err() {
|
||||
warn!(
|
||||
"Couldn't locate Web UI directory ({:?}), disabling...",
|
||||
ui_path
|
||||
);
|
||||
}
|
||||
let desktop_enabled = !matches.is_present("NO_DESKTOP");
|
||||
let ui_enabled = ui_path.exists() && !matches.is_present("NO_UI");
|
||||
let ui_enabled = ui_path.is_ok() && !matches.is_present("NO_UI");
|
||||
let browser_enabled = desktop_enabled && !matches.is_present("NO_BROWSER");
|
||||
|
||||
let preview_path = upend.db_path.join("previews");
|
||||
|
@ -158,6 +163,7 @@ fn main() -> Result<()> {
|
|||
// Start HTTP server
|
||||
|
||||
let mut cnt = 0;
|
||||
let ui_path = ui_path.ok();
|
||||
let server = loop {
|
||||
let state = state.clone();
|
||||
let ui_path = ui_path.clone();
|
||||
|
@ -183,8 +189,8 @@ fn main() -> Result<()> {
|
|||
.service(routes::get_jobs)
|
||||
.service(routes::get_info);
|
||||
|
||||
if ui_enabled {
|
||||
app.service(actix_files::Files::new("/", &ui_path).index_file("index.html"))
|
||||
if let Some(ui_path) = &ui_path {
|
||||
app.service(actix_files::Files::new("/", ui_path).index_file("index.html"))
|
||||
} else {
|
||||
app
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue