Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
include proxy bind address in errors
Raine Virta4323dc85f912
diff --git a/src/main.rs b/src/main.rsindex 2ecaa3a..50cbdc9 100644--- a/src/main.rs+++ b/src/main.rs@@ -99,8 +99,7 @@ fn main() -> Result<()> {ServeMode::Monitor => {let monitor = MonitorHandle::default();let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();- let listener = runtime- .block_on(tokio::net::TcpListener::bind(("127.0.0.1", effective_port)))?;+ let listener = runtime.block_on(server::bind_proxy_listener(effective_port))?;let server_monitor = monitor.clone();let server_task = runtime.spawn(server::serve_listener(listener,diff --git a/src/server.rs b/src/server.rsindex bc29d1a..8b4c0bb 100644--- a/src/server.rs+++ b/src/server.rs@@ -43,10 +43,17 @@ async fn serve_inner(config: ServerConfig,shutdown: impl Future<Output = ()> + Send + 'static,) -> anyhow::Result<()> {- let listener = TcpListener::bind(("127.0.0.1", config.port)).await?;+ let listener = bind_proxy_listener(config.port).await?;serve_listener(listener, config.monitor, shutdown).await}+pub async fn bind_proxy_listener(port: u16) -> anyhow::Result<TcpListener> {+ let addr = format!("127.0.0.1:{port}");+ TcpListener::bind(&addr)+ .await+ .map_err(|err| anyhow::anyhow!("failed to bind proxy listener on {addr}: {err}"))+}+pub async fn serve_listener(listener: TcpListener,monitor: Option<MonitorHandle>,diff --git a/tests/server.rs b/tests/server.rsindex ebfe761..c46a850 100644--- a/tests/server.rs+++ b/tests/server.rs@@ -3,7 +3,7 @@ use axum::http::{Method, Request, StatusCode};use claude_code_proxy::{monitor::{MonitorHandle, RequestStatus},registry::Registry,- server::{app, app_with_monitor},+ server::{app, app_with_monitor, bind_proxy_listener},};use serde_json::{Value, json};use std::sync::Arc;@@ -13,6 +13,17 @@ fn body_string(json: &str) -> Body {Body::from(json.to_string())}+#[tokio::test]+async fn bind_error_names_address_and_port() {+ let occupied = std::net::TcpListener::bind("127.0.0.1:0").unwrap();+ let port = occupied.local_addr().unwrap().port();++ let err = bind_proxy_listener(port).await.unwrap_err().to_string();++ assert!(err.contains(&format!("127.0.0.1:{port}")));+ assert!(err.contains("failed to bind proxy listener"));+}+#[tokio::test]async fn healthz_returns_ok() {let app = app(Arc::new(Registry::with_default_alias()));