Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 23 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -50,10 +50,31 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
async fn handle_request(req: Request<Body>) -> Result<Response<Body>, Infallible> {
let args: Vec<String> = 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('/'),
};
// 读取文件内容
Expand Down