doido-generators 0.1.0

Doido code generators plus the unified CLI (server, console, db, worker, generate, new, credentials).
Documentation
use doido_controller::axum;

/// Boots the HTTP server with the application's `routes`.
///
/// `env` (from `--env`) and `port` (from `--port`) override the environment and
/// listen port for this run. When `routes` is `None` — as it is for the
/// standalone `doido-generators` binary, which carries no application routes —
/// the server is not started.
pub async fn run(routes: Option<axum::Router>, env: Option<String>, port: Option<u16>) {
    match routes {
        Some(router) => {
            // The global tracing subscriber is installed by `cli::run` before
            // dispatch, so the steps below already log through the centralized
            // logger.

            // Apply `--env` before any config-driven boot step, so the DB pool,
            // cache, and server bind all read `config/<env>.yml` for that env.
            // (The logger's verbosity was already installed from the ambient env.)
            if let Some(env) = env.as_deref() {
                std::env::set_var("DOIDO_ENV", env);
            }

            // Install the global DB pool before serving so controllers can reach
            // it via `Context::db()`. A failure here is fatal — handlers would
            // otherwise panic on first use.
            if let Err(e) = doido_model::pool::init().await {
                doido_core::tracing::error!("failed to connect to the database: {e}");
                return;
            }
            // Install the Tera view engine over `app/views` so `Context::render`
            // works. Non-fatal: an app may serve JSON only.
            if let Err(e) = doido_view::init("app/views") {
                doido_core::tracing::warn!("failed to load views from app/views: {e}");
            }
            // Install the global cache store from the `cache` config section
            // (in-memory by default). Non-fatal: an app may not use the cache,
            // and the memory backend never fails.
            if let Err(e) = doido_cache::init_cache().await {
                doido_core::tracing::warn!("failed to initialize cache: {e}");
            }
            if let Err(e) = doido_controller::start_server_with(router, None, port).await {
                doido_core::tracing::error!("server error: {e}");
            }
        }
        None => {
            doido_core::tracing::warn!("no routes configured; server not started");
        }
    }
}