added routes for js and random media

removed login logic from website as the app is needed for that
This commit is contained in:
shockrahwow 2019-11-27 23:13:07 -08:00
parent 1706efc619
commit 9bdeedb3d8
2 changed files with 20 additions and 8 deletions

View File

@ -35,7 +35,7 @@ fn rocket() -> rocket::Rocket {
rocket::ignite() rocket::ignite()
.mount("/static", StaticFiles::from("/static")) .mount("/static", StaticFiles::from("/static"))
.mount("/", routes![ .mount("/", routes![
homepage, login_page, about_page, server_info, homepage, about_page, server_info,
static_css, static_css,
]) ])
.attach(Template::fairing()) .attach(Template::fairing())
@ -61,7 +61,7 @@ mod test {
} }
// Next we test the static resource routes // Next we test the static resource routes
#[test] #[test]
fn static_css() { fn statics() {
let client = Client::new(rocket()).expect("Valid rocket instance"); let client = Client::new(rocket()).expect("Valid rocket instance");
let response = client.get("/static/css/index.css").dispatch(); let response = client.get("/static/css/index.css").dispatch();
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);

View File

@ -45,12 +45,7 @@ pub fn homepage() -> Template {
let ctx = context(); let ctx = context();
Template::render("index", &ctx) Template::render("index", &ctx)
} }
// Handles logging in a user to their home instance
#[get("/login")]
pub fn login_page() -> Template {
let ctx = context();
Template::render("login", &ctx)
}
#[get("/about")] #[get("/about")]
pub fn about_page() -> Template { pub fn about_page() -> Template {
let ctx = context(); let ctx = context();
@ -70,3 +65,20 @@ pub fn static_css(file: String) -> Option<NamedFile> {
f = f.replace("%2e", ""); f = f.replace("%2e", "");
NamedFile::open(Path::new("static/css/").join(f)).ok() NamedFile::open(Path::new("static/css/").join(f)).ok()
} }
#[get("/static/js/<file>")]
pub fn static_js(file: String) -> Option<NamedFile> {
let mut f = file;
f = f.replace("..", "");
f = f.replace("%2e", "");
NamedFile::open(Path::new("static/js/").join(f)).ok()
}
#[get("/static/media/<file>")]
pub fn static_js(file: String) -> Option<NamedFile> {
let mut f = file;
f = f.replace("..", "");
f = f.replace("%2e", "");
NamedFile::open(Path::new("static/media/").join(f)).ok()
}