pub fn start(preferred_port: u16) -> Result<u16>Expand description
Starts the DNS server for the CodeEditorLand private network.
This function performs the following steps:
- Uses portpicker to find an available port (tries
preferred_portfirst) - Sets the
DNS_PORTglobal variable - Builds the DNS catalog with the
editor.landzone - Spawns the DNS server as a background task
- Returns the port number
The DNS server runs in the background and can be stopped by dropping the application.
§Parameters
preferred_port- The preferred port number to use. If this port is already in use, portpicker will find an alternative available port.
§Returns
Returns Ok(port) with the port number the server is listening on,
or an error if the server failed to start.
§Example
use Mist::start;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Start DNS server, preferring port 5353
let port = start(5353)?;
println!("DNS server started on port {}", port);
tokio::signal::ctrl_c().await?;
Ok(())
}