use std::net::{Ipv4Addr, SocketAddr};
use anyhow::Context as _;
use re_redap_client::ConnectionRegistryHandle;
use re_server::{RerunCloudHandlerBuilder, ServerBuilder, ServerHandle};
pub async fn start(
connection_registry: ConnectionRegistryHandle,
) -> anyhow::Result<(ServerHandle, re_uri::Origin)> {
let handler = RerunCloudHandlerBuilder::new().build();
let rerun_cloud_service =
re_protos::cloud::v1alpha1::rerun_cloud_service_server::RerunCloudServiceServer::new(
handler,
);
let addr = SocketAddr::from((Ipv4Addr::LOCALHOST, re_uri::DEFAULT_REDAP_PORT));
let server_handle = ServerBuilder::default()
.with_address(addr)
.with_service(rerun_cloud_service)
.build()
.start()
.await
.context("failed to start the internal catalog")?;
let origin = re_uri::Origin::from_scheme_and_socket_addr(
re_uri::Scheme::RerunHttp,
server_handle.connect_addr(),
);
connection_registry
.client(origin.clone())
.await
.context("failed to connect to the internal catalog")?;
re_log::debug!("internal catalog server listening at {origin}");
Ok((server_handle, origin))
}