Configurable path

This commit is contained in:
2026-10-06 08:24:08 +03:00
parent f88715d58d
commit e68e9c2032
2 changed files with 7 additions and 6 deletions
+4 -2
View File
@@ -1,10 +1,11 @@
use std::env;
use std::{env, path::PathBuf};
use secrecy::SecretString;
use thiserror::Error;
pub struct Config {
pub server_secret: SecretString,
pub state_dir: PathBuf,
}
#[derive(Error, Debug)]
@@ -19,7 +20,8 @@ impl Config {
pub fn new() -> Result<Self, ConfigError> {
dotenvy::dotenv().map_err(|err| ConfigError::Unknown(err.into()))?;
let server_secret = env::var("SERVER_SECRET").map(SecretString::from).map_err(|_| ConfigError::MissingServerSecret)?;
Ok(Self{server_secret})
let state_dir = env::var("RUKOSYNC_STATE_DIR").map_or_else(|_| PathBuf::from("/tmp/"), PathBuf::from);
Ok(Self{server_secret, state_dir})
}
}
+3 -4
View File
@@ -1,5 +1,3 @@
use std::path::Path;
use axum::{Json, Router, response::{IntoResponse as _, Response}, routing};
use rukosync::{api::{syncs, users}, app::AppState, config::Config, };
use tower_http::trace::TraceLayer;
@@ -18,9 +16,10 @@ async fn main() -> anyhow::Result<()> {
.init();
let config = Config::new()?;
let app_state = AppState::new(Path::new("/tmp/kosync.db"), &config).await?;
let db_path = config.state_dir.join("kosync.db");
tracing::info!("Database at {:?}", db_path);
let app_state = AppState::new(&db_path, &config).await?;
tracing::info!("Hello");
let app = Router::new()
.route("/healthcheck", routing::get(healthcheck))