Repository: tauri-apps/tauri
File: tooling/cli/src/dev.rs (Rust)

Code before:
    .frontend_dist
    .clone();
  if !options.no_dev_server && dev_url.is_none() {
    if let Some(FrontendDist::Directory(path)) = &frontend_dist {
      use crate::helpers::web_dev_server;
      if path.exists() {
        let path = path.canonicalize()?;
        let ip = if mobile {
          *local_ip_address(options.force_ip_prompt)
        } else {
          Ipv4Addr::new(127, 0, 0, 1).into()
        };
        let server_url = web_dev_server::start(path, ip, options.port)?;
        let server_url = format!("http://{server_url}");
        dev_url = Some(server_url.parse().unwrap());

        if let Some(c) = &options.config {
          let mut c: tauri_utils::config::Config = serde_json::from_value(c.0.clone())?;
          c.build.dev_url = dev_url.clone();
          options.config = Some(crate::ConfigValue(serde_json::to_value(&c).unwrap()));
        } else {
          options.config = Some(crate::ConfigValue(
            serde_json::from_str(&format!(r#"{{ "build": {{ "devUrl": "{server_url}" }} }}"#))
              .unwrap(),
          ))
        }

        reload_config(options.config.as_ref().map(|c| &c.0))?;
      }
    }
  }

  if !options.no_dev_server_wait {
    if let Some(url) = dev_url {
      let host = url
        .host()
        .unwrap_or_else(|| panic!("No host name in the URL"));
      let port = url
        .port_or_known_default()
        .unwrap_or_else(|| panic!("No port number in the URL"));
      let addrs;
      let addr;
      let addrs = match host {
        url::Host::Domain(domain) => {
          use std::net::ToSocketAddrs;
          addrs = (domain, port).to_socket_addrs()?;
          addrs.as_slice()
        }
        url::Host::Ipv4(ip) => {
          addr = (ip, port).into();
          std::slice::from_ref(&addr)

Review comment (refactor):
We should probably refactor this to change the value in-place without deserializing and serializing again.

Code after:
    .frontend_dist
    .clone();
  if !options.no_dev_server && dev_url.is_none() {
    if let Some(FrontendDist::Directory(path)) = &frontend_dist {
      use crate::helpers::web_dev_server;
      if path.exists() {
        let path = path.canonicalize()?;
        let ip = if mobile {
          *local_ip_address(options.force_ip_prompt)
        } else {
          Ipv4Addr::new(127, 0, 0, 1).into()
        };
        let server_url = web_dev_server::start(path, ip, options.port)?;
        let server_url = format!("http://{server_url}");
        dev_url = Some(server_url.parse().unwrap());

        if let Some(c) = &mut options.config {
          if let Some(build) = c
            .0
            .as_object_mut()
            .and_then(|root| root.get_mut("build"))
            .and_then(|build| build.as_object_mut())
          {
            build.insert("devUrl".into(), server_url.into());
          }
        } else {
          options
            .config
            .replace(crate::ConfigValue(serde_json::json!({
              "build": {
                "devUrl": server_url
              }
            })));
        }

        reload_config(options.config.as_ref().map(|c| &c.0))?;
      }
    }
  }

  if !options.no_dev_server_wait {
    if let Some(url) = dev_url {
      let host = url
        .host()
        .unwrap_or_else(|| panic!("No host name in the URL"));
      let port = url
        .port_or_known_default()
        .unwrap_or_else(|| panic!("No port number in the URL"));
      let addrs;
      let addr;
      let addrs = match host {