Skip to content

Commit cc6a47f

Browse files
author
Samuel Jenks
committed
feat: serve custom html file name without uri modifications
1 parent cadf444 commit cc6a47f

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "godot-https-server"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
[dependencies]
66
hyper = { version = "0.14", features = ["full"] }

‎src/main.rs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hyper::{server::conn::Http, service::service_fn, Body, Request, Response, StatusCode};
2-
use std::{convert::Infallible, fs, net::SocketAddr, path::Path, sync::Arc};
2+
use std::{convert::Infallible, env, fs, net::SocketAddr, path::Path, sync::Arc};
33
use tokio::{fs::File, net::TcpListener};
44
use tokio_rustls::TlsAcceptor;
55
use rcgen::generate_simple_self_signed;
@@ -50,10 +50,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5050
}
5151
}
5252
async fn handle_request(req: Request<Body>) -> Result<Response<Body>, Infallible> {
53+
let args: Vec<String> = env::args().collect();
54+
let mut html_file = "index.html";
55+
56+
for index in 0..args.len() {
57+
let current = &args[index];
58+
let slice = current.as_str();
59+
60+
if slice == "--filename" || slice == "-f" {
61+
html_file = args[index + 1].as_str();
62+
}
63+
}
64+
println!("Serving HTML file: {}", html_file);
65+
5366
let path = req.uri().path();
5467
let query = req.uri().query().unwrap_or_default();
5568
let file_path = match path {
56-
"/" => "index.html",
69+
"/" => html_file,
5770
_ => path.trim_start_matches('/'),
5871
};
5972
// 读取文件内容

0 commit comments

Comments
 (0)