mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-01-18 03:32:30 -08:00
Improve 404 page
This commit is contained in:
parent
de4c97c74b
commit
821c94c609
1 changed files with 8 additions and 3 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue