Skip to content

Commit

Permalink
Compress static files
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Aug 17, 2024
1 parent 570c2b3 commit a3c2b3b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/server/axum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{extract::FromRef, Router};
use tower_http::services::ServeDir;
use tower_http::{compression::CompressionLayer, services::ServeDir};

use crate::app::{self, App};

Expand All @@ -12,11 +12,17 @@ mod version;
pub mod test;

pub fn make_router(app: App) -> Router {
let swagger = ServeDir::new(&app.swagger_dir_path);

let static_files = Router::new()
.nest_service("/", ServeDir::new(&app.web_dir_path))
.layer(CompressionLayer::new());

Router::new()
.nest("/api", api::router())
.with_state(app.clone())
.nest_service("/swagger", ServeDir::new(app.swagger_dir_path))
.nest_service("/", ServeDir::new(app.web_dir_path))
.nest_service("/swagger", swagger)
.nest("/", static_files)
}

pub async fn launch(app: App) -> Result<(), std::io::Error> {
Expand Down

0 comments on commit a3c2b3b

Please sign in to comment.