Lines
0 %
Functions
Branches
100 %
use exitfailure::ExitFailure;
use server::config::set_config;
use std::env;
use tokio::runtime::Handle;
/// Boot the server the same way the original CLI entrypoint did:
/// install drivers, run migrations, load config. Used by both
/// binaries so the initialization sequence stays identical.
///
/// # Errors
/// Returns an `ExitFailure` if `set_config` fails for the optional
/// `setopt` override. Server-boot failures are handled separately:
/// panics from the `boot` join handle surface as task-panic aborts,
/// which is the original behaviour the CLI shipped with.
/// # Panics
/// Panics if `server::start().await` returns a handle that panics,
/// or whose inner task panics, or whose inner `Result` is `Err`.
/// The three `.unwrap()` calls unwind a `JoinHandle → Result →
/// Result` triple set up by the legacy `server::start` API; surface
/// area matches the previous CLI bootstrap one-for-one.
pub async fn start_server(
database: Option<String>,
setopt: Option<(String, String)>,
) -> Result<(), ExitFailure> {
if let Some(db) = database {
unsafe {
env::set_var("DATABASE_URL", db);
}
Handle::current()
.spawn(server::start().await)
.await
.unwrap()
.unwrap();
if let Some((field, content)) = setopt {
set_config(&field, content.into()).await?;
Ok(())