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", "ipnetwork",
"log", "log",
"memchr", "memchr",
"native-tls",
"once_cell", "once_cell",
"paste", "paste",
"percent-encoding", "percent-encoding",

View File

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

Binary file not shown.

View File

@ -20,6 +20,6 @@
}, },
"type": "module", "type": "module",
"dependencies": { "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 axum::response::{IntoResponse, Redirect, Response};
use headers::{self, Header}; use headers::{self, Header};
use http::header::{HeaderName, HeaderValue}; use http::header::{HeaderName, HeaderValue};
@ -127,3 +128,7 @@ impl Header for HXTarget {
values.extend(std::iter::once(self.target.clone())); 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 anyhow::Result;
use axum::{ use axum::{
error_handling::HandleErrorLayer, error_handling::HandleErrorLayer,
response::Response,
routing::{get, post}, routing::{get, post},
BoxError, Router, BoxError, Router,
}; };
@ -28,7 +29,6 @@ use tower_http::{services::ServeDir, trace::TraceLayer};
use tower_livereload::LiveReloadLayer; use tower_livereload::LiveReloadLayer;
use tracing::debug; use tracing::debug;
use lib::actors::importer::ImporterHandle;
use lib::config::Config; use lib::config::Config;
use lib::domain_locks::DomainLocks; use lib::domain_locks::DomainLocks;
use lib::handlers; use lib::handlers;
@ -36,6 +36,7 @@ use lib::log::init_tracing;
use lib::state::AppState; use lib::state::AppState;
use lib::USER_AGENT; use lib::USER_AGENT;
use lib::{actors::crawl_scheduler::CrawlSchedulerHandle, auth::Backend}; 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<()> { async fn serve(app: Router, addr: SocketAddr) -> Result<()> {
debug!("listening on {}", addr); debug!("listening on {}", addr);
@ -67,6 +68,7 @@ async fn main() -> Result<()> {
let pool = PgPoolOptions::new() let pool = PgPoolOptions::new()
.max_connections(config.database_max_connections) .max_connections(config.database_max_connections)
.acquire_timeout(std::time::Duration::from_secs(3))
.connect(&config.database_url) .connect(&config.database_url)
.await?; .await?;
@ -167,7 +169,7 @@ async fn main() -> Result<()> {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
debug!("starting livereload"); debug!("starting livereload");
let livereload = LiveReloadLayer::new(); let livereload = LiveReloadLayer::new().request_predicate(not_htmx_predicate);
let reloader = livereload.reloader(); let reloader = livereload.reloader();
let mut watcher = notify::recommended_watcher(move |_| reloader.reload())?; let mut watcher = notify::recommended_watcher(move |_| reloader.reload())?;
watcher.watch(Path::new("static"), notify::RecursiveMode::Recursive)?; watcher.watch(Path::new("static"), notify::RecursiveMode::Recursive)?;