Added autoreload

This commit is contained in:
Manuel Forcén Muñoz 2024-05-21 22:59:26 +02:00
parent 1ad1e66470
commit c9e621571c
4 changed files with 29 additions and 0 deletions

1
Cargo.lock generated
View file

@ -2231,6 +2231,7 @@ dependencies = [
"axum", "axum",
"chrono", "chrono",
"hyper", "hyper",
"rand",
"serde", "serde",
"serde_json", "serde_json",
"sqlx", "sqlx",

View file

@ -34,5 +34,26 @@
{% endblock body %} {% endblock body %}
</div> </div>
</div> </div>
<script>
let state = {execution: null};
const check_exec = () => {
return fetch('/execution')
.then(response => response.text())
.then(data => parseInt(data))
.catch(err => {});
}
window.onload = () => {
check_exec().then(exec => {
state.execution = exec;
setInterval(()=>{
check_exec().then(exec => {
if(exec && state.execution != exec) {
location.reload();
}
});
}, 1000);
})
}
</script>
</body> </body>
</html> </html>

View file

@ -15,3 +15,4 @@ hyper = "0.14.27"
serde_json = "1" serde_json = "1"
accounters = { path = ".." } accounters = { path = ".." }
tera = "1.19.1" tera = "1.19.1"
rand = "0.8"

View file

@ -28,6 +28,8 @@ async fn main() {
tmpls: Arc::new(tmpls), tmpls: Arc::new(tmpls),
}; };
let exec_id: u32 = rand::random();
let app = Router::new() let app = Router::new()
.nest( .nest(
"/", "/",
@ -69,6 +71,10 @@ async fn main() {
Router::new() Router::new()
.route("/styles.css", get(routes::static_routes::styles)) .route("/styles.css", get(routes::static_routes::styles))
.route("/csv.js", get(routes::static_routes::csv)), .route("/csv.js", get(routes::static_routes::csv)),
)
.route(
"/execution",
get(move || async move { format!("{exec_id}") }),
), ),
) )
.nest( .nest(