Package updates & don't load livereload snippet on hx-requests

This commit is contained in:
Tyler Hallada 2024-01-03 00:07:41 -05:00
parent c9a631a1f2
commit 89f37279e5
6 changed files with 11 additions and 5 deletions

1
Cargo.lock generated
View File

@ -2898,7 +2898,6 @@ dependencies = [
"ipnetwork",
"log",
"memchr",
"native-tls",
"once_cell",
"paste",
"percent-encoding",

View File

@ -44,7 +44,7 @@ reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_with = "3"
sqlx = { version = "0.7", features = [
"runtime-tokio-native-tls",
"runtime-tokio",
"postgres",
"macros",
"migrate",

Binary file not shown.

View File

@ -20,6 +20,6 @@
},
"type": "module",
"dependencies": {
"htmx.org": "^1.9.5"
"htmx.org": "^1.9.10"
}
}

View File

@ -1,3 +1,4 @@
use axum::extract::Request;
use axum::response::{IntoResponse, Redirect, Response};
use headers::{self, Header};
use http::header::{HeaderName, HeaderValue};
@ -127,3 +128,7 @@ impl Header for HXTarget {
values.extend(std::iter::once(self.target.clone()));
}
}
pub fn not_htmx_predicate<Body>(req: &Request<Body>) -> bool {
!req.headers().contains_key(HX_REQUEST)
}

View File

@ -3,6 +3,7 @@ use std::{collections::HashMap, net::SocketAddr, path::Path, sync::Arc};
use anyhow::Result;
use axum::{
error_handling::HandleErrorLayer,
response::Response,
routing::{get, post},
BoxError, Router,
};
@ -28,7 +29,6 @@ use tower_http::{services::ServeDir, trace::TraceLayer};
use tower_livereload::LiveReloadLayer;
use tracing::debug;
use lib::actors::importer::ImporterHandle;
use lib::config::Config;
use lib::domain_locks::DomainLocks;
use lib::handlers;
@ -36,6 +36,7 @@ use lib::log::init_tracing;
use lib::state::AppState;
use lib::USER_AGENT;
use lib::{actors::crawl_scheduler::CrawlSchedulerHandle, auth::Backend};
use lib::{actors::importer::ImporterHandle, htmx::not_htmx_predicate};
async fn serve(app: Router, addr: SocketAddr) -> Result<()> {
debug!("listening on {}", addr);
@ -67,6 +68,7 @@ async fn main() -> Result<()> {
let pool = PgPoolOptions::new()
.max_connections(config.database_max_connections)
.acquire_timeout(std::time::Duration::from_secs(3))
.connect(&config.database_url)
.await?;
@ -167,7 +169,7 @@ async fn main() -> Result<()> {
if cfg!(debug_assertions) {
debug!("starting livereload");
let livereload = LiveReloadLayer::new();
let livereload = LiveReloadLayer::new().request_predicate(not_htmx_predicate);
let reloader = livereload.reloader();
let mut watcher = notify::recommended_watcher(move |_| reloader.reload())?;
watcher.watch(Path::new("static"), notify::RecursiveMode::Recursive)?;