diff --git a/README.md b/README.md index 20d0f23..81ab63b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,26 @@ [![build](https://github.com/Leinnan/lwa_simple_server/actions/workflows/rust.yml/badge.svg)](https://github.com/Leinnan/lwa_simple_server/actions/workflows/rust.yml) -Simple server made with hosting locally webgl games in mind. +``` +Simple server made with hosting locally webgl games in mind + +Usage: lwa_simple_server [OPTIONS] [FOLDER_TO_HOST] + +Arguments: + [FOLDER_TO_HOST] Folder to host, current by default + +Options: + --ssl + Should use SSL, false by default + -a, --address
+ Specifies hosting address, "localhost:8080" by default + -c, --certificates-folder + + -h, --help + Print help + -V, --version + Print version +``` It makes testing Unity webgl games easy, even allows connecting with different domains(less CORS issues during tests). @@ -28,7 +47,7 @@ To start run it in folder that should be root folder of hosted site: ```bash cd desired/folder -lwa_simple_server "folder_to_host" +lwa_simple_server "folder_to_host/current_by_default" ``` diff --git a/src/app.rs b/src/app.rs index f4be86b..695e780 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,8 +5,8 @@ use std::path::PathBuf; #[derive(Debug, Parser, Clone)] #[command(name = "lwa_simple_server", version = "0.1.0", author = "Mev Lyshkin")] pub struct SimpleServer { - /// Folder to host - pub folder_to_host: String, + /// Folder to host, current by default + pub folder_to_host: Option, /// Should use SSL, false by default #[arg(long)] pub ssl: bool, @@ -19,6 +19,13 @@ pub struct SimpleServer { } impl SimpleServer { + pub fn get_folder_to_host(&self) -> PathBuf { + if self.folder_to_host.is_some() { + self.folder_to_host.clone().unwrap() + } else { + PathBuf::from(".") + } + } pub fn get_address(&self) -> String { if self.address.is_some() { return self.address.clone().unwrap(); diff --git a/src/main.rs b/src/main.rs index 33f6c5d..f21fc15 100755 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ async fn main() -> std::io::Result<()> { let app_args = crate::app::SimpleServer::parse(); env::set_var("RUST_LOG", "actix_web=debug,actix_server=info"); env_logger::init(); - let path = app_args.folder_to_host.clone(); + let path = app_args.get_folder_to_host(); { // `openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'` @@ -20,7 +20,7 @@ async fn main() -> std::io::Result<()> { "Starting server on address: {}://{} with hosted folder: {} [SSL={}]", if app_args.ssl{ "https" } else {"http"}, app_args.get_address(), - path, + path.display(), app_args.ssl ); }