git.lucas.co / cce-designer
graphic design tool
git clone https://git.lucas.co/cce-designer.git

commita2cb8d9267456744c5ec6e4b8f43a8a4dd7c3322
parent62ebd7500e
authorLucas Galante <[email protected]>
date2026-07-16 13:25
feat: CCE_DESIGNER_HTTP_PORT overrides the automation API port

Co-Authored-By: Claude Fable 5 <[email protected]>

 src/api.rs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/api.rs b/src/api.rs
index 42e1aa9..9d20cf3 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -4,14 +4,20 @@ use crate::{CustomEvent, HttpAction};
 
 pub fn start_http_server(server_sender: calloop::channel::Sender<CustomEvent>) {
     std::thread::spawn(move || {
-        let listener = match TcpListener::bind("127.0.0.1:3000") {
+        // CCE_DESIGNER_HTTP_PORT overrides the default so a second instance
+        // (tests, debugging) can run alongside one already holding 3000.
+        let port: u16 = std::env::var("CCE_DESIGNER_HTTP_PORT")
+            .ok()
+            .and_then(|p| p.parse().ok())
+            .unwrap_or(3000);
+        let listener = match TcpListener::bind(("127.0.0.1", port)) {
             Ok(l) => l,
             Err(e) => {
-                eprintln!("Failed to bind HTTP server to port 3000: {:?}", e);
+                eprintln!("Failed to bind HTTP server to port {port}: {:?}", e);
                 return;
             }
         };
-        println!("Embedded HTTP Server listening on http://127.0.0.1:3000");
+        println!("Embedded HTTP Server listening on http://127.0.0.1:{port}");
 
         for stream in listener.incoming() {
             let stream = match stream {