removing fn routes for static files
This commit is contained in:
parent
d248821271
commit
42038106cd
@ -5,7 +5,10 @@
|
||||
#[macro_use] extern crate rocket;
|
||||
extern crate rocket_contrib;
|
||||
|
||||
|
||||
use rocket_contrib::serve::StaticFiles;
|
||||
use rocket_contrib::templates::Template;
|
||||
|
||||
mod website;
|
||||
use website::*;
|
||||
|
||||
@ -28,14 +31,17 @@ struct PageAttrs {
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
fn rocket() -> rocket::Rocket {
|
||||
rocket::ignite()
|
||||
.mount("/", routes![
|
||||
homepage, login_page, server_info,
|
||||
static_css, static_js
|
||||
])
|
||||
.mount("/static/css", StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static/css")))
|
||||
.attach(Template::fairing())
|
||||
.launch();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket().launch();
|
||||
}
|
||||
|
||||
// Integrating some basic tests just for this module
|
||||
@ -46,15 +52,17 @@ mod test {
|
||||
use rocket::http::Status;
|
||||
|
||||
#[test]
|
||||
fn homepage() {
|
||||
fn test_homepage() {
|
||||
// Just make sure that when request the home page we actually get the html back
|
||||
let client = Client::new(rocket::ignite()).unwrap();
|
||||
let mut response = client.get("/").dispatch();
|
||||
let client = Client::new(rocket()).expect("Valid rocket instance");
|
||||
let response = client.get("/").dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
}
|
||||
// Next we test the static resource routes
|
||||
#[test]
|
||||
fn static_css() {
|
||||
let client = Client::new(rocket::ignite()).unwrap();
|
||||
let mut response = client.get("/css/index.css").dispatch();
|
||||
let client = Client::new(rocket()).expect("Valid rocket instance");
|
||||
let response = client.get("/css/index.css").dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
}
|
||||
}
|
||||
|
@ -57,13 +57,3 @@ pub fn server_info() -> Template {
|
||||
Template::render("servers", &ctx)
|
||||
}
|
||||
|
||||
// General resources
|
||||
#[get("/static/css/<stylesheet>")]
|
||||
pub fn static_css(stylesheet: String) -> io::Result<NamedFile> {
|
||||
println!("{}", stylesheet);
|
||||
NamedFile::open(format!("static/css/{}", stylesheet))
|
||||
}
|
||||
#[get("/static/js/<javascript>")]
|
||||
pub fn static_js(javascript: String) -> io::Result<NamedFile> {
|
||||
NamedFile::open(format!("static/js/{}", javascript))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user