Rocket/examples/static_files/src/main.rs

23 lines
428 B
Rust
Raw Normal View History

#![feature(plugin)]
#![plugin(rocket_macros)]
extern crate rocket;
use rocket::Rocket;
use std::fs::File;
use std::io::Error as IOError;
2016-09-04 11:06:28 +00:00
#[get("/")]
fn index() -> File {
File::open("static/index.html").unwrap()
}
2016-09-04 11:06:28 +00:00
#[get("/<file>")]
fn files(file: &str) -> Result<File, IOError> {
File::open(format!("static/{}", file))
}
fn main() {
Rocket::new("localhost", 8000).mount_and_launch("/", routes![index, files]);
}