grafbase_local_backend/
server_api.rs1use crate::errors::BackendError;
2use crate::types::ServerMessage;
3use common::types::LocalAddressType;
4use common::utils::find_available_port;
5use server::errors::ServerError;
6use std::sync::mpsc::Receiver;
7use std::thread;
8
9type ServerInfo = (thread::JoinHandle<Result<(), ServerError>>, Receiver<ServerMessage>);
10
11pub fn start_server(start_port: u16, search: bool, watch: bool, tracing: bool) -> Result<ServerInfo, BackendError> {
19 match find_available_port(search, start_port, LocalAddressType::Localhost) {
20 Some(port) => {
21 let (handle, receiver) = server::start(port, watch, tracing);
22 Ok((handle, receiver))
23 }
24 None => {
25 if search {
26 Err(BackendError::AvailablePort)
27 } else {
28 Err(BackendError::PortInUse(start_port))
29 }
30 }
31 }
32}