use std::sync::{Arc, LazyLock, RwLock}; use axum::{ Json, Router, http::StatusCode, response::IntoResponse, routing::{get, post}, }; use axum_macros::debug_handler; use protocol::Signal; use tokio::net::TcpListener; static SIGNALS: LazyLock>>> = LazyLock::new(|| Arc::new(RwLock::new(vec![]))); pub async fn start_signalling() { let route = route(); let listener = TcpListener::bind("0.0.0.0:4546").await.unwrap(); axum::serve(listener, route).await.unwrap(); } fn route() -> Router { Router::new() .route("/alive", get(alive)) .route("/", post(signal)) } async fn alive() -> impl IntoResponse { StatusCode::OK } #[debug_handler] async fn signal(Json(signal): Json) -> impl IntoResponse { SIGNALS.write().unwrap().push(signal); StatusCode::OK }