diff --git a/actix/src/main.rs b/actix/src/main.rs index 4b8b56f..9a444c3 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -60,7 +60,10 @@ async fn getall(data: web::Data, session: Session) -> HttpResponse { // Get the site URL #[get("/api/siteurl")] async fn siteurl() -> HttpResponse { - let site_url = env::var("site_url").unwrap_or(String::from("unset")); + let site_url = env::var("site_url") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or(String::from("unset")); HttpResponse::Ok().body(site_url) } @@ -151,7 +154,11 @@ async fn main() -> Result<()> { // Generate session key in runtime so that restart invalidates older logins let secret_key = Key::generate(); - let db_location = env::var("db_url").unwrap_or(String::from("/urls.sqlite")); + let db_location = env::var("db_url") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or(String::from("unset")); + let port = env::var("port") .unwrap_or(String::from("4567")) .parse::() @@ -170,7 +177,7 @@ async fn main() -> Result<()> { ) // Maintain a single instance of database throughout .app_data(web::Data::new(AppState { - db: database::open_db(env::var("db_url").unwrap_or(db_location.clone())), + db: database::open_db(db_location.clone()), })) .service(link_handler) .service(getall)