From 3a14b62c07ce0e321ba4152a64d4b9878ed0e2c3 Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Tue, 26 Mar 2024 16:58:47 -0500 Subject: [PATCH] add tower live reload to auto refresh page on save --- Cargo.lock | 15 +++++++++++++++ Cargo.toml | 1 + src/router.rs | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c9bc393..4c17283 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1172,6 +1172,7 @@ dependencies = [ "sqlx", "tokio", "tokio-stream", + "tower-livereload", ] [[package]] @@ -3109,6 +3110,20 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" +[[package]] +name = "tower-livereload" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61d6cbbab4b2d3cafd21fb211cc4b06525a0df919c3e8ca3d36485b1c1bd4cd4" +dependencies = [ + "bytes", + "http 1.1.0", + "http-body 1.0.0", + "pin-project-lite", + "tokio", + "tower", +] + [[package]] name = "tower-service" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 31f9197..054df76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ shuttle-shared-db = { version = "0.42.0", features = ["postgres", "sqlx"] } sqlx = { version = "0.7.2", features = ["runtime-tokio-rustls", "postgres"] } tokio = "1.28.2" tokio-stream = { version = "0.1.14", features = ["sync"] } +tower-livereload = "0.9.2" diff --git a/src/router.rs b/src/router.rs index 11fe26f..33849fb 100644 --- a/src/router.rs +++ b/src/router.rs @@ -54,5 +54,7 @@ pub fn init_router() -> Router { .nest("/notes", init_notes_routes()) .nest("/", init_utily_routes()); - Router::new().nest("/", routes) + Router::new() + .nest("/", routes) + .layer(tower_livereload::LiveReloadLayer::new()) }