Move load_config to Config::from_env

This commit is contained in:
2026-07-19 10:00:07 -04:00
parent a0931eb420
commit b15b8b2ae1
2 changed files with 28 additions and 26 deletions

View File

@@ -201,8 +201,9 @@ pub struct Config {
pub server: ServerConfig,
}
impl Config {
/// Parse configuration from the expected files and environment variables
pub fn load_config() -> Result<Config, config::ConfigError> {
pub fn from_env() -> Result<Self, config::ConfigError> {
use config::{Environment, File};
let pkg_name = env!("CARGO_PKG_NAME");
@@ -228,6 +229,7 @@ pub fn load_config() -> Result<Config, config::ConfigError> {
.build()?
.try_deserialize()
}
}
/// Provide a sane default for the public path, using the same sources as Dioxus does internally.
/// Checks the `DIOXUS_PUBLIC_PATH` environment variable, then tries relative to the path of this

View File

@@ -10,7 +10,7 @@ use tower_http::services::ServeFile;
use crate::App;
use crate::app::LOGO_ICO;
use crate::server::{
auth::build_auth_layer, config, database, key_val_store,
auth::build_auth_layer, config::Config, database, key_val_store,
require_auth_mw::require_auth_middleware,
};
use crate::util::error::{Contextualize, Error, ErrorType, Result};
@@ -21,7 +21,7 @@ pub async fn main() -> Result<std::convert::Infallible> {
}
tracing::debug!("Loading configuration...");
let config = config::load_config()
let config = Config::from_env()
.map_err(|e| Error::message_here(e.to_string()))
.err_context("Failed to load config")?;