diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index 2977610bf..bf8b30a8d 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -17,16 +17,17 @@ server_fn = { git = "https://github.com/leptos-rs/leptos", rev = "15a4e54435eb5a dioxus_server_macro = { path = "server-macro" } # warp -warp = { version = "0.3.3", optional = true } +warp = { version = "0.3.5", features = ["compression-gzip"], optional = true } http-body = { version = "0.4.5", optional = true } # axum axum = { version = "0.6.1", features = ["ws", "macros"], optional = true } -tower-http = { version = "0.4.0", optional = true, features = ["fs"] } +tower-http = { version = "0.4.0", optional = true, features = ["fs", "compression-gzip"] } +tower = { version = "0.4.13", optional = true } axum-macros = "0.3.7" # salvo -salvo = { version = "0.37.7", optional = true, features = ["serve-static", "ws"] } +salvo = { version = "0.37.7", optional = true, features = ["serve-static", "ws", "compression"] } serde = "1.0.159" # Dioxus + SSR @@ -63,7 +64,7 @@ default = ["hot-reload", "default-tls"] router = ["dioxus-router"] hot-reload = ["serde_json", "futures-util"] warp = ["dep:warp", "http-body", "ssr"] -axum = ["dep:axum", "tower-http", "ssr"] +axum = ["dep:axum", "tower-http", "tower", "ssr"] salvo = ["dep:salvo", "ssr"] ssr = ["server_fn/ssr", "tokio", "dioxus-ssr", "hyper", "http", "dioxus-router/ssr", "tokio-stream"] default-tls = ["server_fn/default-tls"] diff --git a/packages/fullstack/examples/axum-hello-world/src/main.rs b/packages/fullstack/examples/axum-hello-world/src/main.rs index 1b21a086f..c3c14b7fe 100644 --- a/packages/fullstack/examples/axum-hello-world/src/main.rs +++ b/packages/fullstack/examples/axum-hello-world/src/main.rs @@ -59,7 +59,7 @@ async fn get_server_data() -> Result { fn main() { launch!(@([127, 0, 0, 1], 8080), app, { - server_cfg: ServeConfigBuilder::new(app, (AppProps { count: 0 })), + serve_cfg: ServeConfigBuilder::new(app, (AppProps { count: 0 })), incremental: IncrementalRendererConfig::default().invalidate_after(std::time::Duration::from_secs(120)), }); } diff --git a/packages/fullstack/src/launch.rs b/packages/fullstack/src/launch.rs index 50d472cec..228ddf4f3 100644 --- a/packages/fullstack/src/launch.rs +++ b/packages/fullstack/src/launch.rs @@ -132,10 +132,16 @@ pub async fn launch_server( #[cfg(all(feature = "axum", not(feature = "warp"), not(feature = "salvo")))] { use crate::adapters::axum_adapter::DioxusRouterExt; + use tower::ServiceBuilder; + axum::Server::bind(&addr) .serve( axum::Router::new() .serve_dioxus_application("", cfg) + .layer( + ServiceBuilder::new() + .layer(tower_http::compression::CompressionLayer::new().gzip(true)), + ) .into_make_service(), ) .await @@ -143,14 +149,21 @@ pub async fn launch_server( } #[cfg(all(feature = "warp", not(feature = "axum"), not(feature = "salvo")))] { - warp::serve(crate::prelude::serve_dioxus_application("", cfg)) - .run(addr) - .await; + use warp::Filter; + warp::serve( + crate::prelude::serve_dioxus_application("", cfg) + .with(warp::filters::compression::gzip()), + ) + .run(addr) + .await; } #[cfg(all(feature = "salvo", not(feature = "axum"), not(feature = "warp")))] { use crate::adapters::salvo_adapter::DioxusRouterExt; - let router = salvo::Router::new().serve_dioxus_application("", cfg); + let router = salvo::Router::new().serve_dioxus_application("", cfg).hoop( + salvo::compression::Compression::new() + .with_algos(&[salvo::prelude::CompressionAlgo::Gzip]), + ); salvo::Server::new(salvo::listener::TcpListener::bind(addr)) .serve(router) .await;