Skip to content

Commit 6a5cfac

Browse files
committed
Only use TLS if set by env vars
1 parent dc983e0 commit 6a5cfac

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ async fn main() {
6363

6464
#[cfg(not(debug_assertions))]
6565
{
66-
let tls_config =
67-
RustlsConfig::from_pem_file(PathBuf::from("cert.pem"), PathBuf::from("privkey.pem"))
66+
if std::env::var("TLS").is_ok() {
67+
let tls_config =
68+
RustlsConfig::from_pem_file(PathBuf::from("cert.pem"), PathBuf::from("privkey.pem"))
69+
.await
70+
.expect("unable to open certificate files");
71+
axum_server::bind_rustls(addr, tls_config)
72+
.serve(router.into_make_service())
6873
.await
69-
.expect("unable to open certificate files");
70-
axum_server::bind_rustls(addr, tls_config)
71-
.serve(router.into_make_service())
72-
.await
73-
.expect("unable to bind https server");
74+
.expect("unable to bind https server");
75+
} else {
76+
axum_server::bind(addr)
77+
.serve(router.into_make_service())
78+
.await
79+
.expect("unable to bind http server");
80+
}
7481
}
7582
}
7683

0 commit comments

Comments
 (0)