* Moving frontend to api along

THere's also some deps in there but i cb fucked to doc that
This commit is contained in:
shockrah
2021-10-10 13:21:34 -07:00
parent d06784c06e
commit 8ce7c038f9
8 changed files with 198 additions and 7 deletions

View File

@@ -1,17 +1,20 @@
#![feature(decl_macro)]
#[macro_use] extern crate rocket;
use std::env;
use rocket_dyn_templates::Template;
mod video;
mod page;
fn main() {
#[tokio::main]
async fn main() {
// emoji's crash my terminal
env::set_var("ROCKET_CLI_COLORS", "off");
env::set_var("ROCKET_CLI_COLORS", "false");
/*
* Some of the target vars that we look for
* CLIP_DIR
*/
let _ = rocket::ignite()
.mount("/api", routes![video::list_categories, video::list_videos])
.launch();
let _ = rocket::build()
.mount("/", routes![page::home, page::category, page::video, page::files])
.attach(Template::fairing())
.launch().await;
}

36
api/src/page.rs Normal file
View File

@@ -0,0 +1,36 @@
use serde::Serialize;
use rocket_dyn_templates::Template;
use rocket::fs::NamedFile;
use std::path::{Path, PathBuf};
use std::collections::HashMap;
#[get("/")]
pub async fn home() -> Template {
// WARN: this is just to get the templates to behave but we're still
// doing everything the browser for the home page
let mut h: HashMap<&'static str, &'static str> = HashMap::new();
h.insert("script_src", "/js/index.js");
h.insert("page", "home");
return Template::render("list", &h);
}
#[get("/category/<cat>")]
pub async fn category(cat: String) -> Template {
let mut h: HashMap<&'static str, &'static str> = HashMap::new();
h.insert("script_src", "/js/category.js");
h.insert("page", "category");
return Template::render("list", &h);
}
#[get("/clip/<id>")]
pub async fn video(id: String) -> Template {
return Template::render("video", &{})
}
#[get("/<file..>")]
pub async fn files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/").join(file)).await.ok()
}