Add html page
This commit is contained in:
21
src/main.rs
21
src/main.rs
@ -6,8 +6,18 @@ use health::HealthState;
|
||||
use rocket_contrib::serve::StaticFiles;
|
||||
use rocket_contrib::templates::Template;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::{env, io};
|
||||
use tokio::fs;
|
||||
use tokio::{fs, task, time::sleep};
|
||||
|
||||
fn start_poller(state: Arc<HealthState>) {
|
||||
task::spawn(async move {
|
||||
loop {
|
||||
state.update().await;
|
||||
sleep(Duration::from_secs(state.config.update_period)).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
@ -19,17 +29,20 @@ async fn main() -> io::Result<()> {
|
||||
.await
|
||||
.expect("failed to read config file");
|
||||
let config = ron::from_str(&config).expect("failed to parse config file");
|
||||
let state = HealthState::new(config);
|
||||
let state = Arc::new(HealthState::new(config));
|
||||
|
||||
let rocket = rocket::ignite()
|
||||
//.attach(Template::custom(|engines| {
|
||||
//handlebars_util::register_helpers(engines)
|
||||
//}))
|
||||
.manage(Arc::new(state))
|
||||
.attach(Template::fairing())
|
||||
.manage(Arc::clone(&state))
|
||||
.mount("/static", StaticFiles::from("static"))
|
||||
.mount("/", rocket::routes![routes::pages::index,]);
|
||||
.mount("/", rocket::routes![routes::pages::dashboard]);
|
||||
//.register(rocket::catchers![auth::login_page,]);
|
||||
|
||||
start_poller(state);
|
||||
|
||||
rocket.launch().await.expect("rocket failed to launch");
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user