mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-25 17:01:09 +00:00
Simplify resource errors to fix icon
This commit is contained in:
parent
a099181085
commit
aa09bbfe93
1 changed files with 6 additions and 19 deletions
|
@ -1,4 +1,3 @@
|
|||
use crate::frontend::app::App;
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::{Request, State},
|
||||
|
@ -16,9 +15,9 @@ use tower_http::services::ServeDir;
|
|||
pub async fn file_and_error_handler(
|
||||
State(options): State<LeptosOptions>,
|
||||
req: Request<Body>,
|
||||
) -> Result<Response<Body>, (StatusCode, String)> {
|
||||
) -> Result<Response<Body>, StatusCode> {
|
||||
let root = options.site_root.clone();
|
||||
let (parts, body) = req.into_parts();
|
||||
let (parts, _) = req.into_parts();
|
||||
|
||||
let mut static_parts = parts.clone();
|
||||
static_parts.headers.clear();
|
||||
|
@ -33,29 +32,17 @@ pub async fn file_and_error_handler(
|
|||
if res.status() == StatusCode::OK {
|
||||
Ok(res.into_response())
|
||||
} else {
|
||||
let handler = leptos_axum::render_app_to_stream(options.to_owned(), App);
|
||||
Ok(handler(Request::from_parts(parts, body))
|
||||
.await
|
||||
.into_response())
|
||||
Err(StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_static_file(
|
||||
request: Request<Body>,
|
||||
root: &str,
|
||||
) -> Result<Response<Body>, (StatusCode, String)> {
|
||||
async fn get_static_file(request: Request<Body>, root: &str) -> Result<Response<Body>, StatusCode> {
|
||||
// `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)
|
||||
Ok(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}"),
|
||||
)),
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue