From ab478cf3af5a4a19a0179c80fdc8209848a6df81 Mon Sep 17 00:00:00 2001 From: siva Date: Tue, 20 Jul 2021 17:52:00 +0200 Subject: [PATCH] first commit --- .gitignore | 6 ++++++ Cargo.toml | 8 ++++++++ Rocket.toml | 7 +++++++ src/main.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 Rocket.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04dadfe --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/target + +Cargo.lock + + +.cargo/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..da8d56e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rocket-3d" +version = "0.1.0" +authors = ["siva "] +edition = "2018" + +[dependencies] +rocket = "0.5.0-rc.1" \ No newline at end of file diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..254ea39 --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,7 @@ +[debug] +adress = "localhost" +port = 5000 + + +[default] +template_dir = "templates" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..47869af --- /dev/null +++ b/src/main.rs @@ -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 { + // Attempt to open file readonly + NamedFile::open("templates/index.html") + .await.ok() +} + +// Handle requests for static files +// Dynamic Path gets everything behind root +#[get("/")] +async fn static_files(file: PathBuf) -> Option { + 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]) +} + +