Read StaticFiles from the templates directory

This may seem a bit paradoxical, but since the templates are generated
using parcel, and this just dumps everything into the root, static
files are kept in the same directory as template files.

This may change in the future.
This commit is contained in:
Tristan Daniël Maat 2020-07-11 22:20:32 +01:00
parent 241ecb1099
commit bd5604be63
Signed by: tlater
GPG key ID: 49670FD774E43268

View file

@ -1,5 +1,7 @@
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
use rocket::fairing::AdHoc;
use rocket_contrib::serve::StaticFiles; use rocket_contrib::serve::StaticFiles;
use rocket_contrib::templates::Template; use rocket_contrib::templates::Template;
@ -15,6 +17,18 @@ fn main() {
.attach(Template::fairing()) .attach(Template::fairing())
.mount("/", mail_routes()) .mount("/", mail_routes())
.mount("/", static_templates()) .mount("/", static_templates())
.mount("/", StaticFiles::from("templates")) .attach(AdHoc::on_attach("Static files config", |rocket| {
let static_path = match rocket.config().get_string("template_dir") {
Ok(dir) => dir,
Err(rocket::config::ConfigError::Missing { .. }) => "templates".to_string(),
Err(err) => {
eprintln!("Error reading configuration: {}", err);
eprintln!("Using default templates path.");
"templates".to_string()
},
};
Ok(rocket.mount("/", StaticFiles::from(static_path)))
}))
.launch(); .launch();
} }