From: Greg Burri Date: Sun, 23 Jun 2019 13:51:53 +0000 (+0200) Subject: Add files watcher. X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=8834567b2f53bad60b9d77ff7970077f9af0888d;p=rup.git Add files watcher. --- diff --git a/Cargo.lock b/Cargo.lock index 888164d..aa0a376 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,6 +716,16 @@ name = "linked-hash-map" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "listenfd" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lock_api" version = "0.1.5" @@ -1161,6 +1171,7 @@ dependencies = [ "actix-files 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "askama 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "listenfd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1590,6 +1601,14 @@ name = "utf8-ranges" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "uuid" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "v_escape" version = "0.7.2" @@ -1758,6 +1777,7 @@ dependencies = [ "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" +"checksum listenfd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "492158e732f2e2de81c592f0a2427e57e12cd3d59877378fe7af624b6bbe0ca1" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" @@ -1854,6 +1874,7 @@ dependencies = [ "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde" +"checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363" "checksum v_escape 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8865501b78eef9193c1b45486acf18ba889e5662eba98854d6fc59d8ecf3542d" "checksum v_escape_derive 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "306896ff4b75998501263a1dc000456de442e21d68fe8c8bdf75c66a33a58e23" "checksum v_htmlescape 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7fbbe0fa88dd36f9c8cf61a218d4b953ba669de4d0785832f33cc72bd081e1be" diff --git a/Cargo.toml b/Cargo.toml index 472cb99..e0da306 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,6 @@ edition = "2018" actix-web = "1.0.0" actix-files = "0.1.1" askama = "0.8" -serde = { version = "1.0", features = ["derive"] } \ No newline at end of file +serde = { version = "1.0", features = ["derive"] } + +listenfd = "0.3" \ No newline at end of file diff --git a/launch_debug.ps1 b/launch_debug.ps1 new file mode 100644 index 0000000..0f083fe --- /dev/null +++ b/launch_debug.ps1 @@ -0,0 +1,2 @@ +# To launch RUP and watching source. See https://actix.rs/docs/autoreload/. +systemfd --no-pid -s http::8082 -- cargo watch -x run \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a64950d..24cfdbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ extern crate actix_web; +extern crate listenfd; extern crate askama; +use listenfd::ListenFd; use actix_files as fs; use actix_web::{web, middleware, App, HttpServer, HttpResponse, Responder, Result, web::Query}; use askama::Template; @@ -31,16 +33,24 @@ fn main_page(query: Query) -> Result { } fn main() -> std::io::Result<()> { - HttpServer::new( - || { - App::new() - .wrap(middleware::Compress::default()) - .wrap(middleware::Logger::default()) - .service(web::resource("/").to(main_page)) - .service(fs::Files::new("/static", "static").show_files_listing()) - } - ) - .bind("0.0.0.0:8082") - .expect("Can not bind to port 8082") - .run() + let mut listenfd = ListenFd::from_env(); + let mut server = + HttpServer::new( + || { + App::new() + .wrap(middleware::Compress::default()) + .wrap(middleware::Logger::default()) + .service(web::resource("/").to(main_page)) + .service(fs::Files::new("/static", "static").show_files_listing()) + } + ); + + server = + if let Some(l) = listenfd.take_tcp_listener(0).unwrap() { + server.listen(l).unwrap() + } else { + server.bind("0.0.0.0:8082").unwrap() + }; + + server.run() }