Rocket/examples/static_files/src/main.rs

31 lines
524 B
Rust
Raw Normal View History

#![feature(plugin)]
2016-09-09 03:38:58 +00:00
#![plugin(rocket_codegen)]
extern crate rocket;
2016-09-08 07:02:17 +00:00
2017-02-18 07:01:12 +00:00
#[cfg(test)]
mod tests;
2016-09-12 08:51:02 +00:00
use std::io;
2016-09-08 07:02:17 +00:00
use std::path::{Path, PathBuf};
use rocket::response::NamedFile;
2016-09-04 11:06:28 +00:00
#[get("/")]
2016-09-12 08:51:02 +00:00
fn index() -> io::Result<NamedFile> {
NamedFile::open("static/index.html")
}
2016-09-08 07:02:17 +00:00
#[get("/<file..>")]
fn files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/").join(file)).ok()
}
2017-02-18 07:01:12 +00:00
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index, files])
}
fn main() {
2017-02-18 07:01:12 +00:00
rocket().launch();
}