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>
38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
use anyhow::Context;
|
|
use tempus::{config::Config, db, routes};
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "tempus=info,tower_http=info".into()),
|
|
)
|
|
.init();
|
|
|
|
let config = Config::from_env()?;
|
|
let pool = db::connect(&config.database_url)
|
|
.await
|
|
.with_context(|| format!("cannot open {}", config.database_url))?;
|
|
|
|
let listener = tokio::net::TcpListener::bind(config.addr)
|
|
.await
|
|
.with_context(|| format!("cannot listen on {}", config.addr))?;
|
|
tracing::info!(db = %config.database_url, "Tempus disponible sur http://{}", config.addr);
|
|
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;
|
|
})
|
|
.await?;
|
|
Ok(())
|
|
}
|