diff --git a/Cargo.lock b/Cargo.lock index 150d054..2d09814 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,7 +212,7 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "godot-https-server" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "hyper", diff --git a/Cargo.toml b/Cargo.toml index 8e8e3cc..f24c1f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "godot-https-server" -version = "0.1.0" +version = "0.2.0" edition = "2021" [dependencies] hyper = { version = "0.14", features = ["full"] } diff --git a/README.md b/README.md index 64522ec..024de73 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,24 @@ sudo ./target/release/godot-web-server ## 🎛️ Advanced Usage +### Install as a global tool + +Installing `godot-https-server` as a global tool allows you to serve not just a Godot release build but also development builds. + +``` +cargo install --path . +cd ~/.cache/godot/editor/tmp_web_export/ +``` + +### Specifying a custom html file + +By default, `godot-https-server` defaults to the index.html file in the current directory where the commmand was executed. You can use the `--filename` or `-f` argument to specify a custom html file name. This is useful for serving the Godot development build folder without appending the filename to the localhost address URI. + +``` +cd $home/Library/Caches/Godot/web/ +godot-https-server --filename tmp_js_export.html +``` + ### Custom SSL Certificates Replace the auto-generated certs: diff --git a/src/main.rs b/src/main.rs index c0ac707..e45974d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use hyper::{server::conn::Http, service::service_fn, Body, Request, Response, StatusCode}; -use std::{convert::Infallible, fs, net::SocketAddr, path::Path, sync::Arc}; +use std::{convert::Infallible, env, fs, net::SocketAddr, path::Path, sync::Arc}; use tokio::{fs::File, net::TcpListener}; use tokio_rustls::TlsAcceptor; use rcgen::generate_simple_self_signed; @@ -50,10 +50,31 @@ async fn main() -> Result<(), Box> { } } async fn handle_request(req: Request) -> Result, Infallible> { + let args: Vec = env::args().collect(); + let mut html_file = "index.html"; + + for index in 0..args.len() { + let current = &args[index]; + let slice = current.as_str(); + + if slice == "--filename" || slice == "-f" { + let potential_next = args.get(index + 1); + + match potential_next { + Some(next) => html_file = next, //use this filename + None => { + println!("Missing filename argument."); + break; + } + } + } + } + println!("Serving HTML file: {}", html_file); + let path = req.uri().path(); let query = req.uri().query().unwrap_or_default(); let file_path = match path { - "/" => "index.html", + "/" => html_file, _ => path.trim_start_matches('/'), }; // 读取文件内容