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:
@@ -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);
|
||||
|
||||
@@ -20,20 +20,10 @@ use utoipa::ToSchema;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServerConfig {
|
||||
pub address: String,
|
||||
pub port: Option<u16>,
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
impl FromStr for ServerConfig {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(ServerConfig {
|
||||
address: s.to_string(),
|
||||
password: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub db: Arc<Mutex<rusqlite::Connection>>,
|
||||
|
||||
Reference in New Issue
Block a user