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:
parent
241ecb1099
commit
bd5604be63
16
src/main.rs
16
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue