From 78d8e1243d2c65bf660868742bac323c858ecfbc Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 18:42:03 -0400 Subject: [PATCH 01/13] Remove csr feature --- Cargo.toml | 1 - src/main.rs | 17 +---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 52ad1ad..a21b408 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ flexi_logger = { version = "0.28.0", optional = true, default-features = false } gloo-net = { git = "https://github.com/rustwasm/gloo.git", rev = "a823fab7ecc4068e9a28bd669da5eaf3f0a56380" } [features] -csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"] hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"] ssr = [ "dep:leptos_axum", diff --git a/src/main.rs b/src/main.rs index e647089..d0eed6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,24 +72,9 @@ async fn main() { axum::serve(listener, app.into_make_service()).await.expect("Server failed"); } -#[cfg(not(any(feature = "ssr", feature = "csr")))] +#[cfg(not(feature = "ssr"))] pub fn main() { // no client-side main function // unless we want this to work with e.g., Trunk for pure client-side testing // see lib.rs for hydration function instead - // see optional feature `csr` instead -} - -#[cfg(all(not(feature = "ssr"), feature = "csr"))] -pub fn main() { - // a client-side main function is required for using `trunk serve` - // prefer using `cargo leptos serve` instead - // to run: `trunk serve --open --features csr` - use leptos::*; - use libretunes::app::*; - use wasm_bindgen::prelude::wasm_bindgen; - - console_error_panic_hook::set_once(); - - leptos::mount_to_body(App); } From 618b7d65ce138b9cf97bc1447351b75b348b4fa3 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 18:47:45 -0400 Subject: [PATCH 02/13] Make console_error_panic_hook required for frontend only --- Cargo.toml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a21b408..cb8443e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ build = "src/build.rs" crate-type = ["cdylib", "rlib"] [dependencies] -console_error_panic_hook = "0.1" +console_error_panic_hook = { version = "0.1", optional = true } cfg-if = "1" http = "1.0" leptos = { version = "0.6", features = ["nightly"] } @@ -43,7 +43,12 @@ flexi_logger = { version = "0.28.0", optional = true, default-features = false } gloo-net = { git = "https://github.com/rustwasm/gloo.git", rev = "a823fab7ecc4068e9a28bd669da5eaf3f0a56380" } [features] -hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"] +hydrate = [ + "leptos/hydrate", + "leptos_meta/hydrate", + "leptos_router/hydrate", + "console_error_panic_hook", +] ssr = [ "dep:leptos_axum", "leptos/ssr", From 893c411c7ff3edcdba45c1dea6e6339afc14dc45 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 18:50:44 -0400 Subject: [PATCH 03/13] Disable default features in http crate --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cb8443e..7ff3e02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] console_error_panic_hook = { version = "0.1", optional = true } cfg-if = "1" -http = "1.0" +http = { version = "1.0", default-features = false } leptos = { version = "0.6", features = ["nightly"] } leptos_meta = { version = "0.6", features = ["nightly"] } leptos_axum = { version = "0.6", optional = true } From 94d62ea2d566f9fec0e3a8fbab20a5d6f4144ea2 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 18:53:58 -0400 Subject: [PATCH 04/13] Disable default features in leptos crate --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7ff3e02..13a0c02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"] console_error_panic_hook = { version = "0.1", optional = true } cfg-if = "1" http = { version = "1.0", default-features = false } -leptos = { version = "0.6", features = ["nightly"] } +leptos = { version = "0.6", default-features = false, features = ["nightly"] } leptos_meta = { version = "0.6", features = ["nightly"] } leptos_axum = { version = "0.6", optional = true } leptos_router = { version = "0.6", features = ["nightly"] } From df78afbe60573dab859a121ab542a92721d08bc4 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 19:07:39 -0400 Subject: [PATCH 05/13] Disable default features in wasm-bindgen --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 13a0c02..cc9981c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ leptos = { version = "0.6", default-features = false, features = ["nightly"] } leptos_meta = { version = "0.6", features = ["nightly"] } leptos_axum = { version = "0.6", optional = true } leptos_router = { version = "0.6", features = ["nightly"] } -wasm-bindgen = "=0.2.92" +wasm-bindgen = { version = "=0.2.92", default-features = false } leptos_icons = { version = "0.3.0" } icondata = { version = "0.3.0" } dotenv = { version = "0.15.0", optional = true } From 4685861af3e8fed59d31fd2d4024ea2dbb456f38 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 19:08:22 -0400 Subject: [PATCH 06/13] Make wasm-bindgen required for frontend only --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cc9981c..cea4b59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ leptos = { version = "0.6", default-features = false, features = ["nightly"] } leptos_meta = { version = "0.6", features = ["nightly"] } leptos_axum = { version = "0.6", optional = true } leptos_router = { version = "0.6", features = ["nightly"] } -wasm-bindgen = { version = "=0.2.92", default-features = false } +wasm-bindgen = { version = "=0.2.92", default-features = false, optional = true } leptos_icons = { version = "0.3.0" } icondata = { version = "0.3.0" } dotenv = { version = "0.15.0", optional = true } @@ -48,6 +48,7 @@ hydrate = [ "leptos_meta/hydrate", "leptos_router/hydrate", "console_error_panic_hook", + "wasm-bindgen", ] ssr = [ "dep:leptos_axum", From 7b43906632808ee916de78f8d08d7dc8c2c6b1e5 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 19:14:38 -0400 Subject: [PATCH 07/13] Disable default features in diesel --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cea4b59..71cb8b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ wasm-bindgen = { version = "=0.2.92", default-features = false, optional = true leptos_icons = { version = "0.3.0" } icondata = { version = "0.3.0" } dotenv = { version = "0.15.0", optional = true } -diesel = { version = "2.1.4", features = ["postgres", "r2d2", "time"], optional = true } +diesel = { version = "2.1.4", features = ["postgres", "r2d2", "time"], default-features = false, optional = true } lazy_static = { version = "1.4.0", optional = true } serde = { version = "1.0.195", features = ["derive"] } openssl = { version = "0.10.63", optional = true } From bf9067aa43266d42a4111588c47cd4448f492537 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 19:17:21 -0400 Subject: [PATCH 08/13] Disable default features in serde --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 71cb8b0..234e1d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ icondata = { version = "0.3.0" } dotenv = { version = "0.15.0", optional = true } diesel = { version = "2.1.4", features = ["postgres", "r2d2", "time"], default-features = false, optional = true } lazy_static = { version = "1.4.0", optional = true } -serde = { version = "1.0.195", features = ["derive"] } +serde = { version = "1.0.195", features = ["derive"], default-features = false } openssl = { version = "0.10.63", optional = true } time = { version = "0.3.34", features = ["serde"] } diesel_migrations = { version = "2.1.0", optional = true } From 12384b5a7591c92848aa9cf5f05b453301ea87af Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 19:18:53 -0400 Subject: [PATCH 09/13] Disable default features in time --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 234e1d7..9814f9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ diesel = { version = "2.1.4", features = ["postgres", "r2d2", "time"], default-f lazy_static = { version = "1.4.0", optional = true } serde = { version = "1.0.195", features = ["derive"], default-features = false } openssl = { version = "0.10.63", optional = true } -time = { version = "0.3.34", features = ["serde"] } +time = { version = "0.3.34", features = ["serde"], default-features = false } diesel_migrations = { version = "2.1.0", optional = true } pbkdf2 = { version = "0.12.2", features = ["simple"], optional = true } futures = { version = "0.3.30", default-features = false, optional = true } From 8ffe09381cbcc4acee06f1fddf4534d822203fc7 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 16 May 2024 19:23:48 -0400 Subject: [PATCH 10/13] Remove futures dependency Use tokio::join instead of futures::join --- Cargo.lock | 1 - Cargo.toml | 2 -- src/search.rs | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b2514e..4b7af41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1576,7 +1576,6 @@ dependencies = [ "diesel_migrations", "dotenv", "flexi_logger", - "futures", "http", "icondata", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 9814f9a..2e46758 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ openssl = { version = "0.10.63", optional = true } time = { version = "0.3.34", features = ["serde"], default-features = false } diesel_migrations = { version = "2.1.0", optional = true } pbkdf2 = { version = "0.12.2", features = ["simple"], optional = true } -futures = { version = "0.3.30", default-features = false, optional = true } tokio = { version = "1", optional = true, features = ["rt-multi-thread"] } axum = { version = "0.7.5", optional = true } tower = { version = "0.4.13", optional = true } @@ -61,7 +60,6 @@ ssr = [ "openssl", "diesel_migrations", "pbkdf2", - "futures", "tokio", "axum", "tower", diff --git a/src/search.rs b/src/search.rs index 3b24f08..dd3aeb8 100644 --- a/src/search.rs +++ b/src/search.rs @@ -102,7 +102,7 @@ pub async fn search(query: String, limit: i64) -> Result<(Vec, Vec Date: Thu, 16 May 2024 19:30:46 -0400 Subject: [PATCH 11/13] Reduce axum features to tokio, http1 --- Cargo.lock | 27 --------------------------- Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b7af41..83fa92e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,15 +153,11 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", - "serde_json", - "serde_path_to_error", - "serde_urlencoded", "sync_wrapper 1.0.0", "tokio", "tower", "tower-layer", "tower-service", - "tracing", ] [[package]] @@ -182,7 +178,6 @@ dependencies = [ "sync_wrapper 0.1.2", "tower-layer", "tower-service", - "tracing", ] [[package]] @@ -2320,16 +2315,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_path_to_error" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" -dependencies = [ - "itoa", - "serde", -] - [[package]] name = "serde_qs" version = "0.12.0" @@ -2359,18 +2344,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "server_fn" version = "0.6.10" diff --git a/Cargo.toml b/Cargo.toml index 2e46758..ab25f8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ time = { version = "0.3.34", features = ["serde"], default-features = false } diesel_migrations = { version = "2.1.0", optional = true } pbkdf2 = { version = "0.12.2", features = ["simple"], optional = true } tokio = { version = "1", optional = true, features = ["rt-multi-thread"] } -axum = { version = "0.7.5", optional = true } +axum = { version = "0.7.5", features = ["tokio", "http1"], default-features = false, optional = true } tower = { version = "0.4.13", optional = true } tower-http = { version = "0.5", optional = true, features = ["fs"] } thiserror = "1.0.57" From eb4dcd4776b4882a04dd2afa954f9a30fcf393f2 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sat, 18 May 2024 18:39:14 -0400 Subject: [PATCH 12/13] Remove tower_sessions dependency --- Cargo.lock | 1 - Cargo.toml | 1 - src/main.rs | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83fa92e..ba01566 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1588,7 +1588,6 @@ dependencies = [ "tokio", "tower", "tower-http", - "tower-sessions", "tower-sessions-redis-store", "wasm-bindgen", ] diff --git a/Cargo.toml b/Cargo.toml index ab25f8f..4a0edc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ axum = { version = "0.7.5", features = ["tokio", "http1"], default-features = fa tower = { version = "0.4.13", optional = true } tower-http = { version = "0.5", optional = true, features = ["fs"] } thiserror = "1.0.57" -tower-sessions = { version = "0.11", default-features = false } tower-sessions-redis-store = { version = "0.11", optional = true } async-trait = "0.1.79" axum-login = { version = "0.14.0", optional = true } diff --git a/src/main.rs b/src/main.rs index d0eed6f..9832704 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ async fn main() { use leptos_axum::{generate_route_list, LeptosRoutes}; use libretunes::app::*; use libretunes::fileserv::{file_and_error_handler, get_static_file}; - use tower_sessions::SessionManagerLayer; + use axum_login::tower_sessions::SessionManagerLayer; use tower_sessions_redis_store::{fred::prelude::*, RedisStore}; use axum_login::AuthManagerLayerBuilder; use libretunes::auth_backend::AuthBackend; From 9a462d5ee974de1e48822d46e89c935dea15a8e8 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sat, 18 May 2024 18:51:59 -0400 Subject: [PATCH 13/13] Make async-trait required for backend only --- Cargo.toml | 3 ++- src/auth_backend.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a0edc3..1ffeb2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ tower = { version = "0.4.13", optional = true } tower-http = { version = "0.5", optional = true, features = ["fs"] } thiserror = "1.0.57" tower-sessions-redis-store = { version = "0.11", optional = true } -async-trait = "0.1.79" +async-trait = { version = "0.1.79", optional = true } axum-login = { version = "0.14.0", optional = true } log = { version = "0.4.21", optional = true } flexi_logger = { version = "0.28.0", optional = true, default-features = false } @@ -64,6 +64,7 @@ ssr = [ "tower", "tower-http", "tower-sessions-redis-store", + "async-trait", "axum-login", "log", "flexi_logger", diff --git a/src/auth_backend.rs b/src/auth_backend.rs index 79e5d9c..cf53a40 100644 --- a/src/auth_backend.rs +++ b/src/auth_backend.rs @@ -1,10 +1,17 @@ -use async_trait::async_trait; use axum_login::{AuthnBackend, AuthUser, UserId}; use crate::users::UserCredentials; use leptos::server_fn::error::ServerFnErrorErr; use crate::models::User; +use cfg_if::cfg_if; + +cfg_if! { + if #[cfg(feature = "ssr")] { + use async_trait::async_trait; + } +} + impl AuthUser for User { type Id = i32;