Browse Source

first commit

master
siva 3 years ago
parent
commit
ab478cf3af
4 changed files with 56 additions and 0 deletions
  1. +6
    -0
      .gitignore
  2. +8
    -0
      Cargo.toml
  3. +7
    -0
      Rocket.toml
  4. +35
    -0
      src/main.rs

+ 6
- 0
.gitignore View File

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

+ 8
- 0
Cargo.toml 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
- 0
Rocket.toml View File

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

+ 35
- 0
src/main.rs 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])
}

Loading…
Cancel
Save