diff --git a/src/main.rs b/src/main.rs index 41eb0f1..9161325 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ #![feature(proc_macro_hygiene, decl_macro)] +use rocket::fairing::AdHoc; + use rocket_contrib::serve::StaticFiles; use rocket_contrib::templates::Template; @@ -15,6 +17,18 @@ fn main() { .attach(Template::fairing()) .mount("/", mail_routes()) .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(); }