mirror of
https://github.com/edg-l/teeobserver.git
synced 2024-10-18 06:53:47 +00:00
ok
This commit is contained in:
parent
3f34e69b20
commit
09375e6175
45
src/log-viewer.html
Normal file
45
src/log-viewer.html
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<ul id="event-list" style="max-height: 100vh; overflow-y: auto; border: 1px dashed black; padding: 4px; margin: auto">
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
// Create WebSocket connection.
|
||||||
|
|
||||||
|
var loc = window.location, ws_uri;
|
||||||
|
if (loc.protocol === "https:") {
|
||||||
|
ws_uri = "wss:";
|
||||||
|
} else {
|
||||||
|
ws_uri = "ws:";
|
||||||
|
}
|
||||||
|
ws_uri += "//" + loc.host;
|
||||||
|
ws_uri += loc.pathname + "ws";
|
||||||
|
|
||||||
|
|
||||||
|
const socket = new WebSocket(ws_uri);
|
||||||
|
|
||||||
|
const target = document.querySelector('#event-list');
|
||||||
|
|
||||||
|
// Listen for messages
|
||||||
|
socket.addEventListener("message", (event) => {
|
||||||
|
let li = document.createElement("li");
|
||||||
|
let pre = document.createElement("pre");
|
||||||
|
pre.innerText = event.data;
|
||||||
|
li.appendChild(pre);
|
||||||
|
target.appendChild(li);
|
||||||
|
target.scrollTop = target.scrollHeight;
|
||||||
|
// console.log("Message from server ", event.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Router, response::Html};
|
||||||
use http::Method;
|
use http::Method;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use sqlx::{postgres::PgPoolOptions, PgPool};
|
use sqlx::{postgres::PgPoolOptions, PgPool};
|
||||||
|
@ -199,7 +199,7 @@ async fn run() -> anyhow::Result<()> {
|
||||||
});
|
});
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(|| async { include_str!("../README.md") }))
|
.route("/", get(|| async { Html(include_str!("log-viewer.html")) }))
|
||||||
.route("/ws", get(routes::ws_handler))
|
.route("/ws", get(routes::ws_handler))
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.layer(TimeoutLayer::new(Duration::from_secs(5)))
|
.layer(TimeoutLayer::new(Duration::from_secs(5)))
|
||||||
|
|
Loading…
Reference in a new issue