Skip to content

Commit 8794fde

Browse files
daxpeddajakobhellermann
authored andcommitted
Move environment parsing to Options
1 parent f5b3952 commit 8794fde

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ fn main() -> Result<(), anyhow::Error> {
1919
let title = std::env::var("CARGO_PKG_NAME").unwrap_or_else(|_| "".to_string());
2020
let address =
2121
std::env::var("WASM_SERVER_RUNNER_ADDRESS").unwrap_or_else(|_| "127.0.0.1".to_string());
22+
let https =
23+
std::env::var("WASM_SERVER_RUNNER_HTTPS").unwrap_or_else(|_| String::from("0")) == "1";
2224

23-
let options = Options { title, address };
25+
let options = Options { title, address, https };
2426

2527
let wasm_file = std::env::args()
2628
.nth(1)

src/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn generate_version() -> String {
2020
pub struct Options {
2121
pub title: String,
2222
pub address: String,
23+
pub https: bool,
2324
}
2425

2526
pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<()> {
@@ -61,7 +62,7 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
6162
}
6263
let addr: SocketAddr = address_string.parse().expect("Couldn't parse address");
6364

64-
if std::env::var("WASM_SERVER_RUNNER_HTTPS").unwrap_or_else(|_| String::from("0")) == "1" {
65+
if options.https {
6566
let certificate = rcgen::generate_simple_self_signed([String::from("localhost")])?;
6667
let config = RustlsConfig::from_der(
6768
vec![certificate.serialize_der()?],

0 commit comments

Comments
 (0)