Skip to content

Commit

Permalink
feat: 启用 tower-http 压缩
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjing committed Aug 7, 2024
1 parent 73ae820 commit 3817d22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ headers = "0.4"
mime = "0.3"
reqwest = { version = "0.12", features = ["json"] }
hyper = "1"
tower-http = { version = "0.5", features = ["fs", "trace", "cors"] }
tower-http = { version = "0.5", features = [
"fs",
"trace",
"cors",
"compression-full",
] }
tower-cookies = "0.10"
cookie = "0.18"
axum = { version = "0.7", features = ["macros", "form"] }
Expand Down
2 changes: 2 additions & 0 deletions ultimates/ultimate-web/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axum::Router;
use tower_http::{
compression::CompressionLayer,
cors::{self, CorsLayer},
trace::TraceLayer,
};
Expand All @@ -9,6 +10,7 @@ use ultimate::configuration::UltimateConfig;

pub async fn init_server(conf: &UltimateConfig, app: Router) -> ultimate::Result<()> {
let make_service = app
.layer(CompressionLayer::new())
.layer(CorsLayer::new().allow_methods(cors::Any).allow_origin(cors::Any))
.layer(TraceLayer::new_for_http())
.into_make_service();
Expand Down

0 comments on commit 3817d22

Please sign in to comment.