Miles Murgaw 1 год назад
Родитель
Сommit
5bc9e4556b
2 измененных файлов с 24 добавлено и 6 удалено
  1. 2 2
      packages/cli/src/config.rs
  2. 22 4
      packages/cli/src/server/mod.rs

+ 2 - 2
packages/cli/src/config.rs

@@ -146,8 +146,8 @@ pub struct WebDevResourceConfig {
 pub struct WebHttpsConfig {
     pub enabled: Option<bool>,
     pub mkcert: Option<bool>,
-    pub key_path: Option<PathBuf>,
-    pub cert_path: Option<PathBuf>,
+    pub key_path: Option<String>,
+    pub cert_path: Option<String>,
 }
 
 #[derive(Debug, Clone)]

+ 22 - 4
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<Option<RustlsConfig>> {
     let web_config = &config.dioxus_config.web.https;
@@ -219,14 +222,29 @@ async fn get_rustls(config: &CrateConfig) -> Result<Option<RustlsConfig>> {
     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<Option<RustlsConfig>> {
                 }
             }
 
-            (PathBuf::from("ssl/cert.pem"), PathBuf::from("ssl/key.pem"))
+            (cert_path, key_path)
         }
         // not mkcert
         Some(false) => {