diff --git a/dist/404.css b/dist/404.css new file mode 100644 index 0000000..39f55b1 --- /dev/null +++ b/dist/404.css @@ -0,0 +1,18 @@ +html { + height: 100%; +} + +body { + height: 100%; + padding: 0; + margin: 0; +} + +main { + height: 100%; + display: flex; + flex-direction: column; + gap: 1rem; + align-items: center; + justify-content: center; +} diff --git a/dist/404.html b/dist/404.html new file mode 100644 index 0000000..85f824a --- /dev/null +++ b/dist/404.html @@ -0,0 +1,35 @@ + + + + + + clubmanager + + + + + + + + + + + + + + + + + + + + +
+
404: Page not found
+ +
+ + + diff --git a/src/main.rs b/src/main.rs index 2e593da..2e0ea9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use diesel_async::{ }; use dotenvy::dotenv; use std::net::SocketAddr; -use tower_http::services::ServeDir; +use tower_http::services::{ServeDir, ServeFile}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; include!(concat!(env!("OUT_DIR"), "/templates.rs")); @@ -57,12 +57,14 @@ async fn main() { let state = AppState::init().await; + let fallback_handler = ServeDir::new("dist").not_found_service(ServeFile::new("dist/404.html")); + // build our application with a route let app = Router::new() .nest("/api", api::router()) .route("/", get(root)) .route("/shifts/:id/drinks", get(drinks)) - .fallback_service(ServeDir::new("./dist")) + .fallback_service(fallback_handler) .with_state(state); // run our app with hyper @@ -87,7 +89,7 @@ async fn root(State(state): State) -> impl IntoResponse { .first(&mut conn) .await .optional() - .expect("Query failed") + .expect("Query failed: No open shifts found") }; tracing::debug!("{open_shift:?}");