From 27513863cf89102d0e7b03ba136f650484dc58b8 Mon Sep 17 00:00:00 2001 From: maxstrb Date: Thu, 6 Nov 2025 11:47:06 +0100 Subject: [PATCH] websocket and showable messages working --- public/index.css | 4 ++++ public/index.html | 6 +++--- public/index.js | 4 +++- src/main.rs | 2 ++ src/response.rs | 3 +++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/public/index.css b/public/index.css index 8b5c750..211c114 100644 --- a/public/index.css +++ b/public/index.css @@ -10,6 +10,10 @@ html { height: 100%; } +li { + color: #fff; +} + body { display: flex; flex-direction: row; diff --git a/public/index.html b/public/index.html index 64bab5b..819b5a0 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ Hello World! - + @@ -17,9 +17,9 @@
-
+ -
+
diff --git a/public/index.js b/public/index.js index c6dcef4..58f68f1 100644 --- a/public/index.js +++ b/public/index.js @@ -2,7 +2,9 @@ const socket = new WebSocket("ws://localhost:8080/websocket"); socket.addEventListener("message", (event) => { let messages = document.getElementById("messages"); - messages.appendChild(`
  • ${event.data}
  • `) + let item = document.createElement("li"); + item.innerHTML = event.data; + messages.appendChild(item); }); function myFunction() { diff --git a/src/main.rs b/src/main.rs index 9b07f6a..cdbc08a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,8 @@ async fn handle_http_connection( } }; + println!("{req:?}"); + let matchable = req.path.to_matchable(); let response = match matchable.as_slice() { diff --git a/src/response.rs b/src/response.rs index 9353e70..e301211 100644 --- a/src/response.rs +++ b/src/response.rs @@ -97,6 +97,9 @@ impl Response { Some(a) if a == OsStr::new("css") => { ContentType::Text(crate::shared_enums::TextType::Css) } + Some(a) if a == OsStr::new("js") => { + ContentType::Text(crate::shared_enums::TextType::Javascript) + } Some(_) | None => { return Err(io::Error::new( io::ErrorKind::InvalidInput,