* Moving frontend to api along
THere's also some deps in there but i cb fucked to doc that
This commit is contained in:
@@ -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
36
api/src/page.rs
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user