Expose server

This commit is contained in:
Pierre HUBERT 2023-05-23 14:46:45 +02:00
parent 7f8a37ce01
commit 757692e054
2 changed files with 7 additions and 4 deletions

View File

@ -42,7 +42,7 @@ use std::collections::HashMap;
use std::error::Error; use std::error::Error;
#[cfg(feature = "embedded-server")] #[cfg(feature = "embedded-server")]
mod server; pub mod server;
/// Spell check options /// Spell check options
#[derive(Hash, Debug, Eq, PartialEq)] #[derive(Hash, Debug, Eq, PartialEq)]

View File

@ -12,8 +12,13 @@ pub struct EmbeddedServer {
} }
impl EmbeddedServer { impl EmbeddedServer {
/// Start embedded Grammalecte server /// Start embedded Grammalecte server on a random free port
pub fn start() -> Result<Self, Box<dyn Error>> { pub fn start() -> Result<Self, Box<dyn Error>> {
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<Self, Box<dyn Error>> {
log::info!("Will start server"); log::info!("Will start server");
// First, unpack server // First, unpack server
let dest = mktemp::Temp::new_dir()?; 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); log::info!("Will start to listen on port {}", port);
let server_file = dest let server_file = dest