feat: extended fallback handler

dedicated 404 page
This commit is contained in:
Zynh0722 2023-09-30 16:41:42 -07:00
parent 3aec5256ba
commit 5f1cc358fd
3 changed files with 58 additions and 3 deletions

18
dist/404.css vendored Normal file
View file

@ -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;
}

35
dist/404.html vendored Normal file
View file

@ -0,0 +1,35 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title>clubmanager</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:url" content="">
<meta property="og:image" content="">
<!-- <link rel="icon" href="/favicon.ico" sizes="any">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<!-- <link rel="icon" href="/icon.svg" type="image/svg+xml"> -->
<link rel="stylesheet" href="/404.css" />
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script>
<!-- <link rel="manifest" href="site.webmanifest"> -->
<meta name="theme-color" content="#fafafa">
</head>
<body>
<main>
<div>404: Page not found</div>
<a hx-boost href="/"><button>Return Home</button></a>
</main>
</body>
</html>

View file

@ -14,7 +14,7 @@ use diesel_async::{
}; };
use dotenvy::dotenv; use dotenvy::dotenv;
use std::net::SocketAddr; use std::net::SocketAddr;
use tower_http::services::ServeDir; use tower_http::services::{ServeDir, ServeFile};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
include!(concat!(env!("OUT_DIR"), "/templates.rs")); include!(concat!(env!("OUT_DIR"), "/templates.rs"));
@ -57,12 +57,14 @@ async fn main() {
let state = AppState::init().await; 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 // build our application with a route
let app = Router::new() let app = Router::new()
.nest("/api", api::router()) .nest("/api", api::router())
.route("/", get(root)) .route("/", get(root))
.route("/shifts/:id/drinks", get(drinks)) .route("/shifts/:id/drinks", get(drinks))
.fallback_service(ServeDir::new("./dist")) .fallback_service(fallback_handler)
.with_state(state); .with_state(state);
// run our app with hyper // run our app with hyper
@ -87,7 +89,7 @@ async fn root(State(state): State<AppState>) -> impl IntoResponse {
.first(&mut conn) .first(&mut conn)
.await .await
.optional() .optional()
.expect("Query failed") .expect("Query failed: No open shifts found")
}; };
tracing::debug!("{open_shift:?}"); tracing::debug!("{open_shift:?}");