Skip to main content

haste_health/commands/
server.rs

1use std::sync::Arc;
2
3use clap::Subcommand;
4use figment::{
5    Figment,
6    providers::{Env, Format as _, Toml},
7};
8use haste_fhir_model::r4::generated::terminology::IssueType;
9use haste_fhir_operation_error::OperationOutcomeError;
10use haste_server::{config::ServerConfig, server};
11
12/// Run the FHIR server.
13#[derive(Subcommand, Debug)]
14pub(crate) enum ServerCommands {
15    /// Start the HTTP server. Configuration is read from `haste.toml` and `HASTE_*` env vars
16    Start,
17}
18
19/// Runs the `server` command group.
20pub(crate) async fn run(command: &ServerCommands) -> Result<(), OperationOutcomeError> {
21    let config: ServerConfig = Figment::new()
22        .merge(Toml::file("haste.toml"))
23        .merge(Env::prefixed("HASTE_"))
24        .extract()
25        .map_err(|e| OperationOutcomeError::error(IssueType::exception(), e.to_string()))?;
26
27    let port = config.port;
28
29    match &command {
30        ServerCommands::Start => server::serve(Arc::new(config), port).await,
31    }
32}