From 569bb8884e8840a560d3cc583446b81d32170565 Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Tue, 29 Aug 2023 20:45:01 +0200 Subject: [PATCH] allow specifing port, not address --- Cargo.lock | 2 +- Cargo.toml | 10 +++++++++- README.md | 13 ++++--------- src/app.rs | 19 +++++++------------ src/main.rs | 18 +++++++----------- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fff206e..2aa07bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,7 +891,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "lwa_simple_server" -version = "0.2.0" +version = "0.1.0" dependencies = [ "actix-cors", "actix-files", diff --git a/Cargo.toml b/Cargo.toml index d457d18..920e5cd 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,16 @@ [package] name = "lwa_simple_server" -version = "0.2.0" +version = "0.1.0" authors = ["Mev Lyshkin "] edition = "2018" +repository = "https://github.com/Leinnan/lwa_simple_server" +homepage = "https://github.com/Leinnan/lwa_simple_server" +readme = "README.md" +license = "MIT" +keywords = ["server", "static", "single-page", "https"] +categories = ["command-line-utilities", "development-tools"] +description = "Simple server made with hosting locally webgl games in mind." +exclude = ["/.github"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 81ab63b..dfcd2f7 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,11 @@ 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 + --ssl Should use SSL, false by default + -p, --port Specifies hosting port, "8080" by default -c, --certificates-folder - - -h, --help - Print help - -V, --version - Print version + -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). diff --git a/src/app.rs b/src/app.rs index 695e780..fd4bdf3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -10,10 +10,10 @@ pub struct SimpleServer { /// Should use SSL, false by default #[arg(long)] pub ssl: bool, - /// Specifies hosting address, "localhost:8080" by default + /// Specifies hosting port, "8080" by default #[arg(short, long)] - pub address: Option, - // Specifies folder containing "key.pem" and "cert.pem" required for ssl hosting, defaults to current folder + pub port: Option, + /// Specifies folder containing "key.pem" and "cert.pem" required for ssl hosting, defaults to current folder #[arg(short, long)] certificates_folder: Option, } @@ -27,18 +27,13 @@ impl SimpleServer { } } pub fn get_address(&self) -> String { - if self.address.is_some() { - return self.address.clone().unwrap(); - } - "localhost:8080".to_string() + format!("localhost:{}", self.port.clone().unwrap_or(8080)) } fn get_certificates_folder(&self) -> PathBuf { - if self.certificates_folder.is_some() { - self.certificates_folder.clone().unwrap() - } else { - PathBuf::from(".") - } + self.certificates_folder + .clone() + .unwrap_or(PathBuf::from(".")) } pub fn get_private_key_path(&self) -> PathBuf { diff --git a/src/main.rs b/src/main.rs index f21fc15..2f42fb9 100755 --- a/src/main.rs +++ b/src/main.rs @@ -12,18 +12,14 @@ 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(); + // `openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'` + println!( + "Starting server on address: {}://{}, folder to host: {}", + if app_args.ssl { "https" } else { "http" }, + app_args.get_address(), + app_args.get_folder_to_host().display() + ); 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'` - - println!( - "Starting server on address: {}://{} with hosted folder: {} [SSL={}]", - if app_args.ssl{ "https" } else {"http"}, - app_args.get_address(), - path.display(), - app_args.ssl - ); - } let server = HttpServer::new(move || { App::new()