From 757692e0545a0e228a475846f69131f4a8a515b6 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 23 May 2023 14:46:45 +0200 Subject: [PATCH] Expose server --- src/lib.rs | 2 +- src/server.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 36ba921..e03a68d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ use std::collections::HashMap; use std::error::Error; #[cfg(feature = "embedded-server")] -mod server; +pub mod server; /// Spell check options #[derive(Hash, Debug, Eq, PartialEq)] diff --git a/src/server.rs b/src/server.rs index 5305225..ea7f312 100644 --- a/src/server.rs +++ b/src/server.rs @@ -12,8 +12,13 @@ pub struct EmbeddedServer { } impl EmbeddedServer { - /// Start embedded Grammalecte server + /// Start embedded Grammalecte server on a random free port pub fn start() -> Result> { + Self::start_listen_on_port(get_free_port()?) + } + + /// Start embedded Grammalecte server on a given port + pub fn start_listen_on_port(port: u16) -> Result> { log::info!("Will start server"); // First, unpack server let dest = mktemp::Temp::new_dir()?; @@ -34,8 +39,6 @@ impl EmbeddedServer { } } - // Get a free port - let port = get_free_port()?; log::info!("Will start to listen on port {}", port); let server_file = dest