Skip to content

Warn when API cannot be started on HTTPs #161

@josecelano

Description

@josecelano
// Run the API server
let join_handle = tokio::spawn(async move {
    if !ssl_enabled {
        info!("Starting Torrust APIs server on: http://{}", bind_addr);

        let handle = server::start(bind_addr, &tracker);

        tx.send(ApiServerJobStarted()).expect("the API server should not be dropped");

        if let Ok(()) = handle.await {
            info!("Torrust APIs server on http://{} stopped", bind_addr);
        }
    } else if ssl_enabled && ssl_cert_path.is_some() && ssl_key_path.is_some() {
        info!("Starting Torrust APIs server on: https://{}", bind_addr);

        let ssl_config = RustlsConfig::from_pem_file(ssl_cert_path.unwrap(), ssl_key_path.unwrap())
            .await
            .unwrap();

        let handle = server::start_tls(bind_addr, ssl_config, &tracker);

        tx.send(ApiServerJobStarted()).expect("the API server should not be dropped");

        if let Ok(()) = handle.await {
            info!("Torrust APIs server on https://{} stopped", bind_addr);
        }
    } else {
        warn!(
            "Could not start Torrust APIs server on https://{}, missing SSL Cert or Key!",
            bind_addr
        );
    }
});

The HTTP tracker shows a warning while starting if an SSL configuration is missing.

We should do the same here for the tracker API.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions