From 779337de5e635bd9d789837fb00b200b2cbd4c00 Mon Sep 17 00:00:00 2001 From: xenofem Date: Wed, 27 Apr 2022 00:53:32 -0400 Subject: [PATCH] make static dir and port configurable --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 22e758d..e573e5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,18 +62,19 @@ async fn upload_socket( async fn main() -> std::io::Result<()> { env_logger::init(); - let ip = "0.0.0.0:3000"; - let data: AppData = web::Data::new(RwLock::new(HashMap::new())); + let static_dir = PathBuf::from(std::env::var("STATIC_DIR").unwrap_or_else(|_| String::from("static"))); + let port = std::env::var("PORT").ok().and_then(|p| p.parse::().ok()).unwrap_or(8080); + HttpServer::new(move || { App::new() .app_data(data.clone()) .wrap(Logger::default()) .service(upload_socket) - .service(actix_files::Files::new("/", "./static").index_file("index.html")) + .service(actix_files::Files::new("/", static_dir.clone()).index_file("index.html")) }) - .bind(ip)? + .bind(("127.0.0.1", port))? .run() .await?; Ok(())