Statically share results.

This commit is contained in:
2022-12-03 21:42:13 -08:00
parent c67fa96700
commit 6afd087c5b
4 changed files with 588 additions and 31 deletions

View File

@@ -11,7 +11,8 @@ use std::{
use glog::Flags;
use log::{error, info};
use rocket::{fairing::AdHoc, response::Responder, State};
use rocket::{fairing::AdHoc, fs::FileServer, response::Responder, State};
use rocket_dyn_templates::{context, Template};
use serde::Deserialize;
use thiserror::Error;
@@ -197,9 +198,18 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()>
}
#[get("/")]
fn index() -> &'static str {
info!("Hello world");
"Hello, world!"
fn index(config: &State<Config>) -> Result<Template, SyncError> {
let dirs: Vec<_> = fs::read_dir(&config.www_root)?
.filter_map(|ent| ent.ok())
.map(|ent| ent.file_name().into_string())
.filter_map(|ent| ent.ok())
.collect();
Ok(Template::render(
"index",
context! {
dirs
},
))
}
#[catch(500)]
@@ -225,8 +235,15 @@ fn rocket() -> _ {
..Default::default()
})
.unwrap();
let config = rocket::Config::figment()
.extract::<Config>()
.expect("Couldn't parse config");
rocket::build()
.mount("/", routes![index, get_reload, post_reload])
.mount("/results/", FileServer::from(config.www_root))
//.register("/", catchers![http500])
.attach(AdHoc::config::<Config>())
.attach(Template::fairing())
}