websocket and showable messages working
This commit is contained in:
parent
01e9b47bc7
commit
27513863cf
5 changed files with 15 additions and 4 deletions
|
|
@ -10,6 +10,10 @@ html {
|
|||
height: 100%;
|
||||
}
|
||||
|
||||
li {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<link rel="stylesheet" href="/public/index.css">
|
||||
<meta charset="UTF-8"/>
|
||||
<title>Hello World!</title>
|
||||
<script src="./index.js"></script>
|
||||
<script src="/public/index.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
<main>
|
||||
|
||||
<form onsubmit="myFunction()">
|
||||
<form onsubmit="myFunction(); return false;">
|
||||
<label for="fname">Message:</label>
|
||||
<input type="text" id="fname" name="fname" id="inp"><br>
|
||||
<input type="text" id="inp" name="fname"><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ const socket = new WebSocket("ws://localhost:8080/websocket");
|
|||
|
||||
socket.addEventListener("message", (event) => {
|
||||
let messages = document.getElementById("messages");
|
||||
messages.appendChild(`<li>${event.data}</li>`)
|
||||
let item = document.createElement("li");
|
||||
item.innerHTML = event.data;
|
||||
messages.appendChild(item);
|
||||
});
|
||||
|
||||
function myFunction() {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ async fn handle_http_connection(
|
|||
}
|
||||
};
|
||||
|
||||
println!("{req:?}");
|
||||
|
||||
let matchable = req.path.to_matchable();
|
||||
|
||||
let response = match matchable.as_slice() {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue