|
|
@ -0,0 +1,35 @@ |
|
|
|
// use rocket macros globally
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
// Owned Mutable Path buffer holds path
|
|
|
|
use std::path::{ Path, PathBuf };
|
|
|
|
|
|
|
|
// Content-Type based on file extension
|
|
|
|
use rocket::fs::NamedFile;
|
|
|
|
|
|
|
|
|
|
|
|
// Render index.html on / request
|
|
|
|
#[get("/")]
|
|
|
|
// Load File asynchronously
|
|
|
|
async fn index() -> Option<NamedFile> {
|
|
|
|
// Attempt to open file readonly
|
|
|
|
NamedFile::open("templates/index.html")
|
|
|
|
.await.ok()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle requests for static files
|
|
|
|
// Dynamic Path gets everything behind root
|
|
|
|
#[get("/<file..>")]
|
|
|
|
async fn static_files(file: PathBuf) -> Option<NamedFile> {
|
|
|
|
NamedFile::open(Path::new("templates/assets/").join(file)).await.ok()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[launch]
|
|
|
|
// Mount routes to Rocket instance
|
|
|
|
fn rocket() -> _{
|
|
|
|
// Launch Rocket
|
|
|
|
rocket::build().mount("/", routes![index, static_files])
|
|
|
|
}
|
|
|
|
|
|
|
|
|