allow specifing port, not address
This commit is contained in:
parent
417800fcad
commit
569bb8884e
|
|
@ -891,7 +891,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
|||
|
||||
[[package]]
|
||||
name = "lwa_simple_server"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-cors",
|
||||
"actix-files",
|
||||
|
|
|
|||
10
Cargo.toml
10
Cargo.toml
|
|
@ -1,8 +1,16 @@
|
|||
[package]
|
||||
name = "lwa_simple_server"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
authors = ["Mev Lyshkin <mev_lyshkin@protonmail.com>"]
|
||||
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
|
||||
|
||||
|
|
|
|||
13
README.md
13
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 <ADDRESS>
|
||||
Specifies hosting address, "localhost:8080" by default
|
||||
--ssl Should use SSL, false by default
|
||||
-p, --port <PORT> Specifies hosting port, "8080" by default
|
||||
-c, --certificates-folder <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).
|
||||
|
|
|
|||
19
src/app.rs
19
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<String>,
|
||||
// Specifies folder containing "key.pem" and "cert.pem" required for ssl hosting, defaults to current folder
|
||||
pub port: Option<i32>,
|
||||
/// Specifies folder containing "key.pem" and "cert.pem" required for ssl hosting, defaults to current folder
|
||||
#[arg(short, long)]
|
||||
certificates_folder: Option<PathBuf>,
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
12
src/main.rs
12
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();
|
||||
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"},
|
||||
"Starting server on address: {}://{}, folder to host: {}",
|
||||
if app_args.ssl { "https" } else { "http" },
|
||||
app_args.get_address(),
|
||||
path.display(),
|
||||
app_args.ssl
|
||||
app_args.get_folder_to_host().display()
|
||||
);
|
||||
}
|
||||
let path = app_args.get_folder_to_host();
|
||||
|
||||
let server = HttpServer::new(move || {
|
||||
App::new()
|
||||
|
|
|
|||
Loading…
Reference in New Issue