diff --git a/packages/cli/src/config.rs b/packages/cli/src/config.rs index 19cc3c7b5..f9117f6e5 100644 --- a/packages/cli/src/config.rs +++ b/packages/cli/src/config.rs @@ -146,8 +146,8 @@ pub struct WebDevResourceConfig { pub struct WebHttpsConfig { pub enabled: Option, pub mkcert: Option, - pub key_path: Option, - pub cert_path: Option, + pub key_path: Option, + pub cert_path: Option, } #[derive(Debug, Clone)] diff --git a/packages/cli/src/server/mod.rs b/packages/cli/src/server/mod.rs index a732db1f3..c5b6fb57a 100644 --- a/packages/cli/src/server/mod.rs +++ b/packages/cli/src/server/mod.rs @@ -209,6 +209,9 @@ pub async fn serve_hot_reload( Ok(()) } +const DEFAULT_KEY_PATH: &str = "ssl/key.pem"; +const DEFAULT_CERT_PATH: &str = "ssl/cert.pem"; + /// Returns an enum of rustls config and a bool if mkcert isn't installed async fn get_rustls(config: &CrateConfig) -> Result> { let web_config = &config.dioxus_config.web.https; @@ -219,14 +222,29 @@ async fn get_rustls(config: &CrateConfig) -> Result> { let (cert_path, key_path) = match web_config.mkcert { // mkcert, use it Some(true) => { - _ = fs::create_dir("ssl"); + // Get paths to store certs, otherwise use ssl/item.pem + let key_path = web_config + .key_path + .clone() + .unwrap_or(DEFAULT_KEY_PATH.to_string()); + + let cert_path = web_config + .cert_path + .clone() + .unwrap_or(DEFAULT_CERT_PATH.to_string()); + + // Create ssl directory if using defaults + if key_path == DEFAULT_KEY_PATH && cert_path == DEFAULT_CERT_PATH { + fs::create_dir("ssl")?; + } + let cmd = Command::new("mkcert") .args([ "-install", "-key-file", - "ssl/key.pem", + &key_path, "-cert-file", - "ssl/cert.pem", + &cert_path, "localhost", "::1", "127.0.0.1", @@ -246,7 +264,7 @@ async fn get_rustls(config: &CrateConfig) -> Result> { } } - (PathBuf::from("ssl/cert.pem"), PathBuf::from("ssl/key.pem")) + (cert_path, key_path) } // not mkcert Some(false) => {