first draft of silencing 404 errors
This commit is contained in:
parent
3306c030e1
commit
f889eb3d12
|
@ -21,6 +21,9 @@ extern crate staticfile;
|
||||||
#[cfg(feature = "serve")]
|
#[cfg(feature = "serve")]
|
||||||
extern crate ws;
|
extern crate ws;
|
||||||
|
|
||||||
|
#[cfg(feature = "serve")]
|
||||||
|
use iron::{Iron, AfterMiddleware, IronResult, IronError, Request, Response, status, Set, Chain};
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
@ -233,6 +236,18 @@ fn watch(args: &ArgMatches) -> Result<(), Box<Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serve")]
|
||||||
|
struct ErrorRecover;
|
||||||
|
|
||||||
|
#[cfg(feature = "serve")]
|
||||||
|
impl AfterMiddleware for ErrorRecover {
|
||||||
|
fn catch(&self, _: &mut Request, err: IronError) -> IronResult<Response> {
|
||||||
|
match err.response.status {
|
||||||
|
Some(_) => Ok(err.response.set(status::NotFound)),
|
||||||
|
_ => Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Watch command implementation
|
// Watch command implementation
|
||||||
#[cfg(feature = "serve")]
|
#[cfg(feature = "serve")]
|
||||||
|
@ -286,9 +301,9 @@ fn serve(args: &ArgMatches) -> Result<(), Box<Error>> {
|
||||||
|
|
||||||
book.build()?;
|
book.build()?;
|
||||||
|
|
||||||
let staticfile = staticfile::Static::new(book.get_destination().expect("destination is present, checked before"));
|
let mut chain = Chain::new(staticfile::Static::new(book.get_destination().expect("destination is present, checked before")));
|
||||||
let iron = iron::Iron::new(staticfile);
|
chain.link_after(ErrorRecover);
|
||||||
let _iron = iron.http(&*address).unwrap();
|
let _iron = Iron::new(chain).http(&*address).unwrap();
|
||||||
|
|
||||||
let ws_server = ws::WebSocket::new(|_| |_| Ok(())).unwrap();
|
let ws_server = ws::WebSocket::new(|_| |_| Ok(())).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue