Ajoute un livereload de développement
Feature cargo `livereload` (tower-livereload, désactivée par défaut) : script injecté dans les pages hors requêtes htmx, assets en no-cache. À lancer avec watchexec (cf. README). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fdba078b51
commit
f4c94f9b5b
5 files changed
+47
-2
No files matched your search
+9
-1
@@ -20,7 +20,15 @@ async fn main() -> anyhow::Result<()> {
|
||||
.await
|
||||
.with_context(|| format!("cannot listen on {}", config.addr))?;
|
||||
tracing::info!(db = %config.database_url, "Tempus disponible sur http://{}", config.addr);
|
||||
axum::serve(listener, routes::app(pool))
|
||||
let app = routes::app(pool);
|
||||
#[cfg(feature = "livereload")]
|
||||
let app = app.layer(
|
||||
// Les fragments htmx ne doivent pas recevoir le script injecté.
|
||||
tower_livereload::LiveReloadLayer::new().request_predicate(
|
||||
|req: &axum::http::Request<axum::body::Body>| !req.headers().contains_key("hx-request"),
|
||||
),
|
||||
);
|
||||
axum::serve(listener, app)
|
||||
.with_graceful_shutdown(async {
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
})
|
||||
|
||||
+8
-1
@@ -56,11 +56,18 @@ pub fn app(pool: SqlitePool) -> Router {
|
||||
.with_state(pool)
|
||||
}
|
||||
|
||||
// En livereload, le CSS/JS doit être relu à chaque rechargement.
|
||||
const CACHE_CONTROL: &str = if cfg!(feature = "livereload") {
|
||||
"no-cache"
|
||||
} else {
|
||||
"public, max-age=3600"
|
||||
};
|
||||
|
||||
async fn asset(content_type: &'static str, body: &'static str) -> impl IntoResponse {
|
||||
(
|
||||
[
|
||||
(header::CONTENT_TYPE, content_type),
|
||||
(header::CACHE_CONTROL, "public, max-age=3600"),
|
||||
(header::CACHE_CONTROL, CACHE_CONTROL),
|
||||
],
|
||||
body,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user