move config things to config.rs

This commit is contained in:
2026-04-25 17:10:44 +02:00
parent 983e1ae88f
commit 41711dd7fb
2 changed files with 53 additions and 26 deletions

View File

@@ -1,8 +1,6 @@
use std::error::Error;
use axum::Router;
use dotenvy::var;
use log::LevelFilter;
use sqlx::PgPool;
use tokio::net::TcpListener;
@@ -17,9 +15,6 @@ mod tags;
mod users;
mod web;
/// Mnemosyne, the mother of the nine muses
const DEFAULT_PORT: u16 = 0x9999; // 39321
/// The string to be returned alongside HTTP 500
const ISE_MSG: &str = "Internal server error";
@@ -30,31 +25,16 @@ pub struct MnemoState {
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
if let Err(e) = dotenvy::dotenv()
&& !e.not_found()
{
return Err(e.into());
}
env_logger::builder()
.filter_level(LevelFilter::Info)
.filter_module("sqlx", LevelFilter::Warn)
.parse_default_env()
.format(config::envlogger_write_format)
.init();
config::dotenv()?;
config::env_logger()?;
let pool = PgPool::connect(var("DATABASE_URL")?.as_str()).await?;
let pool = config::init_pool().await?;
sqlx::migrate!("src/database/migrations").run(&pool).await?;
log::info!("Migrations applied successfully.");
users::auth::init_password_dummies();
users::setup::initialise_reserved_users_if_needed(&pool).await?;
let port = match std::env::var("PORT") {
Ok(p) => p.parse::<u16>()?,
Err(e) => match e {
std::env::VarError::NotPresent => DEFAULT_PORT,
_ => return Err(e)?,
},
};
let port = config::port()?;
let r = Router::new()
.merge(api::api_router())
.merge(web::web_router())