Skip to content

Commit 7f77b86

Browse files
committed
Move fallback handler for cleanliness.
1 parent 0e24386 commit 7f77b86

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

kord-web/docker/Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

kord-web/src/server.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io::Read;
22

3-
use axum::{response::IntoResponse, routing::get, Router};
3+
use axum::{http::Uri, response::IntoResponse, routing::get, Router};
44
use axum_insights::AppInsights;
55
use futures::TryStreamExt;
66
use leptos::config::get_configuration;
@@ -59,16 +59,7 @@ async fn handle(wasi_request: IncomingRequest, wasi_response_outparam: ResponseO
5959
move || shell(leptos_options.clone())
6060
})
6161
.route("/api/hello/:name", get(hello))
62-
.fallback(|uri: axum::http::Uri| async move {
63-
let path = uri.path().split_at(1).1;
64-
65-
StaticAssets::get(path)
66-
.map(|file| (axum::http::StatusCode::OK, [(axum::http::header::CONTENT_TYPE, file.metadata.mimetype())], file.data).into_response())
67-
.unwrap_or_else(|| {
68-
println!("No route matched, returning 404!: {uri}.");
69-
(axum::http::StatusCode::NOT_FOUND, "Not Found".to_string()).into_response()
70-
})
71-
})
62+
.fallback(static_fallback)
7263
.layer(telemetry_layer)
7364
.with_state(leptos_options);
7465

@@ -79,6 +70,17 @@ async fn handle(wasi_request: IncomingRequest, wasi_response_outparam: ResponseO
7970
Ok(())
8071
}
8172

73+
async fn static_fallback(uri: Uri) -> impl IntoResponse {
74+
let path = uri.path().split_at(1).1;
75+
76+
StaticAssets::get(path)
77+
.map(|file| (axum::http::StatusCode::OK, [(axum::http::header::CONTENT_TYPE, file.metadata.mimetype())], file.data).into_response())
78+
.unwrap_or_else(|| {
79+
println!("No route matched, returning 404!: {uri}.");
80+
(axum::http::StatusCode::NOT_FOUND, "Not Found".to_string()).into_response()
81+
})
82+
}
83+
8284
fn prepare_request(wasi_request: IncomingRequest) -> Result<axum::http::Request<axum::body::Body>, String> {
8385
let mut tower_request = axum::http::Request::builder()
8486
.uri(wasi_request.path_with_query().ok_or("The incoming request from the Wasm runtime did not have a request path.")?)

0 commit comments

Comments
 (0)