Statically share results.
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user