Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fileserv::get_static_file for tower_http ^0.4 #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/fileserv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use axum::{
response::IntoResponse,
};
use leptos::*;
use std::convert::Infallible;
use tower::ServiceExt;
use tower_http::services::ServeDir;
use tower_http::services::{fs::ServeFileSystemResponseBody, ServeDir};

pub async fn file_and_error_handler(
State(options): State<LeptosOptions>,
Expand Down Expand Up @@ -42,19 +43,12 @@ pub async fn file_and_error_handler(
async fn get_static_file(
request: Request<Body>,
root: &str,
) -> Result<Response<Body>, (StatusCode, String)> {
) -> Result<Response<ServeFileSystemResponseBody>, Infallible> {
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
// This path is relative to the cargo root
match ServeDir::new(root)
ServeDir::new(root)
.precompressed_gzip()
.precompressed_br()
.oneshot(request)
.await
{
Ok(res) => Ok(res.into_response()),
Err(err) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Error serving files: {err}"),
)),
}
}