make directories configurable

This commit is contained in:
xenofem 2022-04-16 01:57:34 -04:00
parent 774f3195de
commit 4eeabbb770
3 changed files with 24 additions and 10 deletions

View file

@ -1,4 +1,4 @@
use std::{sync::Arc, time::Duration};
use std::{path::PathBuf, sync::Arc, time::Duration};
use actix_web::{
get, http::header::ContentType, middleware::Logger, web, App, HttpResponse, HttpServer,
@ -41,7 +41,8 @@ async fn try_update(state: &AppState, fetcher: &mut PdfFetcher) -> Result<(), Er
}
async fn start_updater() -> Result<web::Data<AppState>, Error> {
let mut fetcher = PdfFetcher::new()?;
let cached_pdf_path = PathBuf::from(std::env::var("CACHED_PDF_PATH").unwrap_or_else(|_| String::from("data.pdf")));
let mut fetcher = PdfFetcher::new(cached_pdf_path)?;
let state = web::Data::new(AppState {
dataset: RwLock::new(Arc::new(load_data(&mut fetcher).await?)),
});
@ -65,6 +66,8 @@ async fn start_updater() -> Result<web::Data<AppState>, Error> {
async fn main() -> std::io::Result<()> {
simple_logger::init_with_level(log::Level::Info).unwrap();
let static_dir = PathBuf::from(std::env::var("STATIC_DIR").unwrap_or_else(|_| String::from("static")));
let state = start_updater().await.expect("Failed to initialize state");
HttpServer::new(move || {
@ -73,7 +76,7 @@ async fn main() -> std::io::Result<()> {
.wrap(Logger::default())
.service(csv)
.service(json)
.service(actix_files::Files::new("/", "./static/").index_file("index.html"))
.service(actix_files::Files::new("/", static_dir.clone()).index_file("index.html"))
})
.bind("127.0.0.1:8080")?
.run()