mirror of https://github.com/rwf2/Rocket.git
Return a 404 when a file isn't found.
This commit is contained in:
parent
004cae7627
commit
d24d5534f4
|
@ -6,7 +6,8 @@ extern crate rocket;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use rocket::response::NamedFile;
|
use rocket::response::{NamedFile, Failure};
|
||||||
|
use rocket::http::StatusCode::NotFound;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> io::Result<NamedFile> {
|
fn index() -> io::Result<NamedFile> {
|
||||||
|
@ -14,8 +15,8 @@ fn index() -> io::Result<NamedFile> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<file..>")]
|
#[get("/<file..>")]
|
||||||
fn files(file: PathBuf) -> io::Result<NamedFile> {
|
fn files(file: PathBuf) -> Result<NamedFile, Failure> {
|
||||||
NamedFile::open(Path::new("static/").join(file))
|
NamedFile::open(Path::new("static/").join(file)).map_err(|_| Failure(NotFound))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Reference in New Issue