compress assets by default in the launch macro

This commit is contained in:
Evan Almloff committed 2023-06-30 19:22:43 -07:00
1 parent cbeaa07be0
commit 040055ba9d
3 files changed
+23 -9

No files matched your search

+5 -4
View File
@@ -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"]
@@ -59,7 +59,7 @@ async fn get_server_data() -> Result<String, ServerFnError> {
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)),
});
}
+17 -4
View File
@@ -132,10 +132,16 @@ pub async fn launch_server<P: Clone + serde::Serialize + Send + Sync + 'static>(
#[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<P: Clone + serde::Serialize + Send + Sync + 'static>(
}
#[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;