feat: implement server configuration with address and port options

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-15 17:55:13 -03:00
parent b9d79d2fe1
commit 29ce003fa8
3 changed files with 41 additions and 20 deletions

View File

@@ -26,11 +26,27 @@ pub fn mode_server(
conn: &mut rusqlite::Connection,
data_path: PathBuf,
) -> Result<()> {
let server_address = settings.get_server_address(&crate::args::Args::parse(), config)
.unwrap_or_else(|| "127.0.0.1:8080".to_string());
// Get server address from args or config with default
let server_address = if let Some(addr) = &settings.server_address {
addr.clone()
} else if let Some(server_config) = &config.server {
server_config.address.clone().unwrap_or_else(|| "127.0.0.1".to_string())
} else {
"127.0.0.1".to_string()
};
// Get server port from args or config with default
let server_port = if let Some(port) = settings.server_port {
port
} else if let Some(server_config) = &config.server {
server_config.port.unwrap_or(21080)
} else {
21080
};
let server_config = common::ServerConfig {
address: server_address,
port: Some(server_port),
password: settings.server_password.clone(),
};
@@ -46,7 +62,14 @@ async fn run_server(
conn: rusqlite::Connection,
data_dir: PathBuf,
) -> Result<()> {
debug!("SERVER: Starting REST HTTP server on {}", config.address);
// Construct address with port
let bind_address = if let Some(port) = config.port {
format!("{}:{}", config.address, port)
} else {
format!("{}:21080", config.address)
};
debug!("SERVER: Starting REST HTTP server on {}", bind_address);
// Use the existing database connection
let db_conn = Arc::new(Mutex::new(conn));
@@ -73,12 +96,12 @@ async fn run_server(
.layer(CorsLayer::permissive())
);
let addr: SocketAddr = if config.address.starts_with('/') || config.address.starts_with("./") {
let addr: SocketAddr = if bind_address.starts_with('/') || bind_address.starts_with("./") {
// Unix socket - not supported by axum directly, fall back to TCP
warn!("Unix sockets not yet implemented, falling back to TCP on 127.0.0.1:8080");
"127.0.0.1:8080".parse()?
warn!("Unix sockets not yet implemented, falling back to TCP on 127.0.0.1:21080");
"127.0.0.1:21080".parse()?
} else {
config.address.parse()?
bind_address.parse()?
};
info!("SERVER: HTTP server listening on {}", addr);