mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 12:41:10 +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::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::{Request, State},
|
extract::{Request, State},
|
||||||
|
@ -16,9 +15,9 @@ use tower_http::services::ServeDir;
|
||||||
pub async fn file_and_error_handler(
|
pub async fn file_and_error_handler(
|
||||||
State(options): State<LeptosOptions>,
|
State(options): State<LeptosOptions>,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
) -> Result<Response<Body>, (StatusCode, String)> {
|
) -> Result<Response<Body>, StatusCode> {
|
||||||
let root = options.site_root.clone();
|
let root = options.site_root.clone();
|
||||||
let (parts, body) = req.into_parts();
|
let (parts, _) = req.into_parts();
|
||||||
|
|
||||||
let mut static_parts = parts.clone();
|
let mut static_parts = parts.clone();
|
||||||
static_parts.headers.clear();
|
static_parts.headers.clear();
|
||||||
|
@ -33,29 +32,17 @@ pub async fn file_and_error_handler(
|
||||||
if res.status() == StatusCode::OK {
|
if res.status() == StatusCode::OK {
|
||||||
Ok(res.into_response())
|
Ok(res.into_response())
|
||||||
} else {
|
} else {
|
||||||
let handler = leptos_axum::render_app_to_stream(options.to_owned(), App);
|
Err(StatusCode::NOT_FOUND)
|
||||||
Ok(handler(Request::from_parts(parts, body))
|
|
||||||
.await
|
|
||||||
.into_response())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_static_file(
|
async fn get_static_file(request: Request<Body>, root: &str) -> Result<Response<Body>, StatusCode> {
|
||||||
request: Request<Body>,
|
|
||||||
root: &str,
|
|
||||||
) -> Result<Response<Body>, (StatusCode, String)> {
|
|
||||||
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
|
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
|
||||||
// This path is relative to the cargo root
|
// This path is relative to the cargo root
|
||||||
match ServeDir::new(root)
|
Ok(ServeDir::new(root)
|
||||||
.precompressed_gzip()
|
.precompressed_gzip()
|
||||||
.precompressed_br()
|
.precompressed_br()
|
||||||
.oneshot(request)
|
.oneshot(request)
|
||||||
.await
|
.await
|
||||||
{
|
.into_response())
|
||||||
Ok(res) => Ok(res.into_response()),
|
|
||||||
Err(err) => Err((
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("Error serving files: {err}"),
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue