This commit is contained in:
2026-06-18 12:02:58 +01:00
parent df0a578207
commit f24da78970
9 changed files with 1250 additions and 96 deletions
+20 -9
View File
@@ -6,11 +6,11 @@ use axum::{
Router,
routing::{get, post},
};
use std::sync::Arc;
use std::{net::SocketAddr, sync::Arc};
use tower_http::services::ServeDir;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use state::AppState;
use state::{AppState, CHAT_RESET_INTERVAL};
#[tokio::main]
async fn main() {
@@ -23,16 +23,27 @@ async fn main() {
let state = Arc::new(AppState::new());
let reset_state = state.clone();
tokio::spawn(async move {
loop {
tokio::time::sleep(CHAT_RESET_INTERVAL).await;
reset_state.clear_everything();
tracing::info!("Cleared all in-memory chat sessions, messages, notifiers, and rate limits");
}
});
let app = Router::new()
.route("/", get(handlers::pages::customer_page))
.route("/agent", get(handlers::pages::agent_page))
.route("/ws/customer/:session_id", get(handlers::ws::customer_ws))
.route("/ws/agent/:agent_id", get(handlers::ws::agent_ws))
.route("/", get(handlers::pages::index_page))
.route("/user", get(handlers::pages::user_page))
.route("/supporter", get(handlers::pages::supporter_page))
.route("/reset-countdown", get(handlers::pages::reset_countdown))
.route("/ws/user/:session_id", get(handlers::ws::user_ws))
.route("/ws/supporter/:supporter_id", get(handlers::ws::supporter_ws))
.route("/messages/:session_id", get(handlers::chat::get_messages))
.route("/send/:session_id", post(handlers::chat::send_message))
.route(
"/agent/send/:session_id",
post(handlers::chat::agent_send_message),
"/supporter/send/:session_id",
post(handlers::chat::supporter_send_message),
)
.route("/sessions", get(handlers::chat::get_sessions))
.route("/sessions/new", post(handlers::chat::new_session))
@@ -43,7 +54,7 @@ async fn main() {
tracing::info!("Chat service running — http://0.0.0.0:3111");
axum::Server::from_tcp(listener.into_std().unwrap())
.unwrap()
.serve(app.into_make_service())
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await
.unwrap();
}