A LiveReload middleware built on top of [tower].
Note that [axum] is only used as an example here, pretty much any Rust HTTP library or framework will be compatible!
```rust use axum::{response::Html, routing::get, Router}; use tower_livereload::LiveReloadLayer;
async fn main() -> Result<(), BoxWow, such webdev
") }))
.layer(LiveReloadLayer::new());
axum::Server::bind(&"0.0.0.0:3030".parse()?)
.serve(app.into_make_service())
.await?;
Ok(())
} ```
More examples can be found on GitHub under [examples].
tower-livereload
has been built from the ground up to provide the highest
amount of ecosystem compatibility.
The provided middleware uses the [http
] and [http_body
] crates as its
HTTP abstractions. That means it is compatible with any library or framework
that also uses those crates, such as [hyper
], [axum
], [tonic
], and
[warp
].
Moreover, we do not depend on any async runtime, keeping your dependency graph small and simplifying debugging.
To provide LiveReload functionality, we have to inject code into HTML web
pages. To determine whether a page is injectable, some header-based
heuristics are used. In particular, [Content-Type
] has to start with
text/html
, [Content-Length
] must be set, and [Content-Encoding
] must
not be set.
If LiveReload is not working for some of your pages, ensure that these
heuristics apply to your responses. In particular, if you use middleware to
compress your HTML, ensure that the [LiveReload
] middleware is
applied before your compression middleware.
tower-livereload
is free and open source software distributed under the terms of either the MIT or the Apache 2.0 license, at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.