Rocket/examples/static_files/src/main.rs

31 lines
524 B
Rust

#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[cfg(test)]
mod tests;
use std::io;
use std::path::{Path, PathBuf};
use rocket::response::NamedFile;
#[get("/")]
fn index() -> io::Result<NamedFile> {
NamedFile::open("static/index.html")
}
#[get("/<file..>")]
fn files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/").join(file)).ok()
}
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index, files])
}
fn main() {
rocket().launch();
}