first commit

This commit is contained in:
siva 2021-07-20 17:52:00 +02:00
parent 702a42fe9c
commit ab478cf3af
4 changed files with 56 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
/target
Cargo.lock
.cargo/

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "rocket-3d"
version = "0.1.0"
authors = ["siva <alexandra.hosp@protonmail.com>"]
edition = "2018"
[dependencies]
rocket = "0.5.0-rc.1"

7
Rocket.toml Normal file
View file

@ -0,0 +1,7 @@
[debug]
adress = "localhost"
port = 5000
[default]
template_dir = "templates"

35
src/main.rs Normal file
View file

@ -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])
}