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(())