use mnote_web::{build_app, AppConfig, AppState};
use tokio::net::TcpListener;
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    init_tracing();

    let config = AppConfig::from_env();
    let bind_addr = config.bind_addr.clone();
    let app = build_app(AppState::new(config));
    let listener = TcpListener::bind(&bind_addr).await?;

    info!(bind_addr = %bind_addr, "mnote-web 最小骨架已启动");
    axum::serve(listener, app).await?;
    Ok(())
}

fn init_tracing() {
    tracing_subscriber::fmt()
        .with_target(false)
        .compact()
        .try_init()
        .ok();
}
