Improve 404 page

This commit is contained in:
Zoey 2021-08-19 12:48:38 -07:00
parent de4c97c74b
commit 821c94c609

View file

@ -10,6 +10,7 @@ use std::{
use futures::SinkExt; use futures::SinkExt;
use hotwatch::{Event, Hotwatch}; use hotwatch::{Event, Hotwatch};
use warp::{ use warp::{
hyper::StatusCode,
path::FullPath, path::FullPath,
reply::Response, reply::Response,
ws::{Message, WebSocket}, ws::{Message, WebSocket},
@ -242,9 +243,13 @@ impl Site {
async move { async move {
// Handle missing files // Handle missing files
println!("404 - {}", path.as_str()); println!("404 - {}", path.as_str());
Ok::<_, std::convert::Infallible>(warp::reply::html( let body = match std::fs::read_to_string(build_path.join("404.html")) {
std::fs::read_to_string(build_path.join("404.html")).unwrap(), Ok(body) => body,
)) _ => "404 Not Found".to_string(),
};
let mut res = Response::new(body.into());
*res.status_mut() = StatusCode::NOT_FOUND;
Ok::<_, std::convert::Infallible>(res)
} }
})); }));