some frontend fixes

This commit is contained in:
2026-08-24 13:49:35 +01:00
parent 02b7ba317c
commit eb85449d67
8 changed files with 197 additions and 64 deletions
+38 -9
View File
@@ -4,14 +4,36 @@ mod state;
use axum::{
Router,
http::{StatusCode, Uri, header},
response::IntoResponse,
routing::{get, post},
};
use std::{net::SocketAddr, sync::Arc};
use tower_http::services::ServeDir;
use rust_embed::RustEmbed;
use std::{borrow::Cow, net::SocketAddr, sync::Arc};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use state::{AppState, CHAT_RESET_INTERVAL};
#[derive(RustEmbed)]
#[folder = "static/"]
struct StaticAsset;
async fn static_handler(uri: Uri) -> impl IntoResponse {
let path = uri.path().trim_start_matches('/');
match StaticAsset::get(path) {
Some(content) => {
let mime = mime_guess::from_path(path).first_or_octet_stream();
(
StatusCode::OK,
[(header::CONTENT_TYPE, mime.as_ref())],
Cow::into_owned(content.data),
)
.into_response()
}
None => (StatusCode::NOT_FOUND, "asset not found").into_response(),
}
}
#[tokio::main]
async fn main() {
tracing_subscriber::registry()
@@ -34,12 +56,13 @@ async fn main() {
}
});
let static_router = Router::new().route("/*path", get(static_handler));
let app = Router::new()
.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))
// New API endpoint for creating sessions without a form
.route("/api/session/create", post(handlers::chat::create_session))
.route("/ws/user/:session_id", get(handlers::ws::user_ws))
.route(
@@ -57,15 +80,21 @@ async fn main() {
post(handlers::chat::supporter_send_message),
)
.route("/sessions", get(handlers::chat::get_sessions))
// Removed: .route("/sessions/new", post(handlers::chat::new_session))
.nest_service("/static", ServeDir::new("static"))
.nest("/static", static_router)
.with_state(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3111").await.unwrap();
let listener = tokio::net::TcpListener::bind("0.0.0.0:3111")
.await
.expect("failed to bind listener on 0.0.0.0:3111");
tracing::info!("Chat service running — http://0.0.0.0:3111");
axum::Server::from_tcp(listener.into_std().unwrap())
.unwrap()
let std_listener = listener
.into_std()
.expect("failed to convert TcpListener to std");
axum::Server::from_tcp(std_listener)
.expect("failed to create axum server from TCP listener")
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await
.unwrap();
.expect("server error");
}