fix websocket handlers be routed as http handlers as well causing 500 errors

Commit f965784 · patx · 2025-06-24T23:46:29-04:00

Changeset
f965784db214579ef6e14fd44888a19cf2432bd9
Parents
760bd4c05353c2897e65f15f289e4f5c9af43125

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/MicroPie.py b/MicroPie.py
index 55a26e6..990719e 100644
--- a/MicroPie.py
+++ b/MicroPie.py
@@ -452,7 +452,7 @@ class App:
                 func_name: str = request._route_handler
             else:
                 func_name: str = parts[0] if parts else "index"
-                if func_name.startswith("_"):
+                if func_name.startswith("_") or func_name.startswith("ws_"):
                     await self._send_response(send, 404, "404 Not Found")
                     return
 
diff --git a/examples/websockets/test.html b/examples/websockets/test.html
index 1bb63b4..f4ca25a 100644
--- a/examples/websockets/test.html
+++ b/examples/websockets/test.html
@@ -8,7 +8,7 @@
     <button onclick="sendMessage()">Send</button>
     <div id="output"></div>
     <script>
-        const ws = new WebSocket("ws://localhost:8000/chat/myroom?user=Alice");
+        const ws = new WebSocket("ws://localhost:8000/chat/MyRoom?user=Alice");
         ws.onmessage = function(event) {
             document.getElementById("output").innerText += event.data + "\n";
         };