This commit is contained in:
uwaa 2024-10-29 03:34:03 +00:00
parent 02a692bf01
commit d11b9a1bab
3 changed files with 64 additions and 4 deletions

View file

@ -2,9 +2,29 @@
<html> <html>
<head> <head>
<title>MiniHTTP Test</title> <title>MiniHTTP Test</title>
<style>
body {
color: white;
background-color: #151515;
font-family: sans-serif;
}
a {
color: #79d3ff;
}
a:visited {
color: #719bff;
}
</style>
</head> </head>
<body> <body>
Websocket test <h1>Example website</h1>
<script src="./websocket.js"></script> <div style="padding-left:20px;">
<a href="./websocket">Websocket test</a><br>
<a href="./custom/foo/bar">Custom route</a><br>
<a href="./test">test.htm</a><br>
<br>
<a href="./subpath/foo">Foo</a><br>
<a href="./subpath/bar">Bar</a><br>
</div>
</body> </body>
</html> </html>

View file

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>MiniHTTP Test</title>
<style>
body {
color: white;
background-color: #151515;
font-family: sans-serif;
}
#log {
color: #afc3ff;
background-color: #2a2d35;
font-family: monospace,monospace;
padding: 10px;
border-radius: 5px;
border: solid white 1px;
width: fit-content;
min-width: 300px;
}
</style>
</head>
<body>
<h1>Websocket test</h1>
<div id="log"></div>
<script src="./websocket.js"></script>
</body>
</html>

View file

@ -1,10 +1,22 @@
const ws = new WebSocket(`wss://${location.host}/`, "test"); function log(text) {
document.getElementById("log").innerText += text + "\n";
}
log("Connecting");
const ws = new WebSocket(`wss://${location.host}/`, "test");
function send(text) {
log(">> " + text);
ws.send(text);
}
ws.onerror = (e) => { ws.onerror = (e) => {
log("Error: " + e);
throw e; throw e;
}; };
ws.onopen = (event) => { ws.onopen = (event) => {
ws.send("Hello world"); log("Connected");
send("Hello world");
}; };
ws.onmessage = (event) => { ws.onmessage = (event) => {
log("<< " + event.data);
console.log(event.data); console.log(event.data);
}; };