use crate::router::ServiceRouter;
use connectrpc::ConnectRpcService;
pub struct StandaloneServer {
service: ConnectRpcService,
config: super::ServerConfig,
}
impl StandaloneServer {
pub fn new(router: ServiceRouter) -> Self {
let connect_router = router.into_inner();
let service = ConnectRpcService::new(connect_router);
Self {
service,
config: super::ServerConfig::default(),
}
}
pub fn with_config(router: ServiceRouter, config: super::ServerConfig) -> Self {
let connect_router = router.into_inner();
let service = ConnectRpcService::new(connect_router);
Self { service, config }
}
pub fn service(&self) -> &ConnectRpcService {
&self.service
}
pub fn config(&self) -> &super::ServerConfig {
&self.config
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_standalone_server_new() {
let service_router = ServiceRouter::new();
let server = StandaloneServer::new(service_router);
assert_eq!(server.config.name, "sunbeam-server");
}
#[test]
fn test_standalone_server_with_config() {
let config = crate::server::ServerConfig {
addr: "127.0.0.1:9000".parse().unwrap(),
name: "test-standalone".to_string(),
max_connections: 500,
tls: false,
};
let service_router = ServiceRouter::new();
let server = StandaloneServer::with_config(service_router, config.clone());
assert_eq!(server.config.name, config.name);
}
}