Skip to content

Commit

Permalink
refactor(env): new hatsu_env_file option
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed May 11, 2024
1 parent 07a07d0 commit f3a5b4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/src/admins/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ It is required unless it has a suffix (optional).

However, it may exist as a built-in preset (in the source code) or an example preset (in [`.env.example`](https://github.com/importantimport/hatsu/blob/main/.env.example))

## HATSU_ENV_FILE

- default: `/etc/hatsu/.env`

Hatsu will first try to find the dotenv file in the current directory, and if unsuccessful will try to use the path indicated by `HATSU_ENV_FILE`.

## HATSU_DATABASE_URL

- default: `sqlite::memory:`
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#[global_allocator]
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;

use std::ops::Deref;
use std::{env, ops::Deref, path::Path};

use activitypub_federation::config::FederationConfig;
use hatsu_apub::actors::ApubUser;
Expand All @@ -23,7 +23,10 @@ async fn main() -> Result<(), AppError> {

tracing::info!("loading environment variables");
if dotenvy::dotenv().is_err() {
tracing::debug!("no .env file found");
let env_file = env::var("HATSU_ENV_FILE").unwrap_or_else(|_| String::from("/etc/hatsu/.dev"));
if dotenvy::from_path(Path::new(&env_file)).is_err() {
tracing::debug!("no .env file found");
}
}

let env = AppEnv::init()?;
Expand Down

0 comments on commit f3a5b4f

Please sign in to comment.