Skip to main content

spawn_node_sidecar

Function spawn_node_sidecar 

Source
pub fn spawn_node_sidecar(app: &AppHandle, sidecar_name: &str) -> Result<()>
Expand description

Spawns a Node.js sidecar with DNS override configured to use the local Hickory DNS server.

This function:

  1. Creates the app data directory if it doesn’t exist
  2. Writes the DNS override JavaScript file to the app data directory
  3. Configures the sidecar process with NODE_OPTIONS to require the DNS override script
  4. Sets the LAND_DNS_SERVER environment variable with the local DNS server address
  5. Spawns the sidecar process

§Parameters

  • app - The Tauri app handle, used to access the app data directory and shell
  • sidecar_name - The name of the sidecar executable to spawn

§Returns

Returns Ok(()) if the sidecar was spawned successfully, or an error if:

  • The app data directory couldn’t be created or accessed
  • The DNS override file couldn’t be written
  • The sidecar couldn’t be found or spawned

§Example

use tauri::Manager;
use SideCar::Spawn::spawn_node_sidecar;

#[tauri::command]
fn launch_sidecar(app:tauri::AppHandle) -> Result<(), String> {
	spawn_node_sidecar(&app, "my-sidecar").map_err(|e| e.to_string())?;
	Ok(())
}