(feat): some connection improvements

This commit is contained in:
Alois 2026-07-30 00:41:56 +02:00
commit d55b1326f8
Signed by: alois
SSH key fingerprint: SHA256:GBzT2DXvAuGV9XIV5W3WrzVpjU54FThmxHXdbz95J24
4 changed files with 27 additions and 1 deletions

View file

@ -7,6 +7,7 @@ use axum::{
response::{IntoResponse, Response},
routing::{delete, get, post},
};
use serde::Serialize;
use tower_http::{
services::{ServeDir, ServeFile},
trace::TraceLayer,
@ -23,6 +24,7 @@ pub async fn serve(
let index = frontend.join("index.html");
let assets = ServeDir::new(frontend).fallback(ServeFile::new(index));
let app = Router::new()
.route("/api/config", get(public_config))
.route("/api/admin", get(admin))
.route("/api/incidents", get(list).post(create))
.route("/api/incidents/{id}", delete(remove))
@ -35,6 +37,17 @@ pub async fn serve(
axum::serve(listener, app).await
}
#[derive(Serialize)]
struct PublicConfig {
public_port: u16,
}
async fn public_config(State(state): State<Arc<AppState>>) -> Json<PublicConfig> {
Json(PublicConfig {
public_port: state.public_port,
})
}
async fn admin() -> StatusCode {
StatusCode::NO_CONTENT
}

View file

@ -20,6 +20,7 @@ use tokio::sync::{RwLock, watch};
pub struct AppState {
categories: Arc<RwLock<Vec<Category>>>,
incidents: IncidentStore,
public_port: u16,
updates: watch::Sender<String>,
}
@ -70,6 +71,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let state = Arc::new(AppState {
categories: Arc::clone(&categories),
incidents,
public_port: config.public_port,
updates,
});