Skip to content

Commit

Permalink
add compression to server
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Jul 12, 2023
1 parent e1c1a17 commit c559f6b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 13 deletions.
90 changes: 80 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ serde = { workspace = true }
serde_json = { workspace = true }
sha2 = "0.10.2"
tokio = { version = "1.26", features = ["full"] }
tower-http = { version = "0.4.0", features = ["fs", "trace"] }
tower-http = { version = "0.4.0", features = [
"fs",
"trace",
"compression-gzip",
"compression-br",
] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use axum::Router;
use buenzlimarks_server::{config::Config, frontend::frontend_handler, router::api_router};
use clap::Parser;
use std::net::SocketAddr;
use tower_http::trace::TraceLayer;
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::main]
Expand All @@ -19,7 +19,8 @@ async fn main() {
"/api",
api_router(&config).layer(TraceLayer::new_for_http()),
)
.fallback(frontend_handler);
.fallback(frontend_handler)
.layer(CompressionLayer::new());

// run it
let addr = SocketAddr::from(([127, 0, 0, 1], config.port));
Expand Down

0 comments on commit c559f6b

Please sign in to comment.