From dddb5d4cbd3a685244054f4d0610ed528c078748 Mon Sep 17 00:00:00 2001 From: M5Max128 Date: Sat, 23 May 2026 02:54:34 +0800 Subject: [PATCH] refactor: centralize port config + fix 8082 conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add EMBED_URL, OLLAMA_URL, LLM_HEALTH_URL to config.rs - Fix health.rs hardcoded ports → config references - Fix sync_db.rs Ollama URL → config::OLLAMA_URL - Create config/port_registry.tsv (single source of truth for ports) - Remove Caddy 8082 proxy block (port belongs to LLM) - Fix .env LLM_URL: localhost → 127.0.0.1 (avoid IPv6 Caddy conflict) --- .env.development | 2 +- config/port_registry.tsv | 22 ++++++++++++++++++++++ src/api/health.rs | 4 ++-- src/core/config.rs | 25 +++++++++++++++++-------- src/core/db/sync_db.rs | 2 +- 5 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 config/port_registry.tsv diff --git a/.env.development b/.env.development index 4004f0c..93c0ab9 100644 --- a/.env.development +++ b/.env.development @@ -73,7 +73,7 @@ REDIS_CACHE_TTL_VIDEO_META=3600 TMDB_API_KEY=e9cde52197f6f8df4d9db99da93db1fb MOMENTRY_TMDB_PROBE_ENABLED=true # LLM for 5W1H summary (points to M5 Gemma4) -MOMENTRY_LLM_SUMMARY_URL=http://localhost:8082/v1/chat/completions +MOMENTRY_LLM_SUMMARY_URL=http://127.0.0.1:8082/v1/chat/completions MOMENTRY_LLM_SUMMARY_MODEL=google_gemma-4-26B-A4B-it-Q5_K_M.gguf MOMENTRY_LLM_SUMMARY_ENABLED=true diff --git a/config/port_registry.tsv b/config/port_registry.tsv new file mode 100644 index 0000000..dc1b202 --- /dev/null +++ b/config/port_registry.tsv @@ -0,0 +1,22 @@ +# Port Registry - Momentry Core +# Each port must have exactly one owner. +# Before adding a service: pick a free port, add a row here, then configure. +# +# Port Service Owner Config Key Default Source +22 ssh sshd - - macOS +80 http Caddy - - Caddyfile +443 https Caddy - - Caddyfile +2019 caddy-admin Caddy - - Caddyfile (internal) +3000 gitea gitea - 3000 start_momentry.sh +3002 production momentry MOMENTRY_SERVER_PORT 3002 run-server-3002.sh +3003 playground momentry_playground MOMENTRY_SERVER_PORT 3003 start_momentry.sh +3200 dashboard Caddy - - Caddyfile +3306 mariadb mariadbd - 3306 start_momentry.sh +5432 postgresql postgres DATABASE_URL postgres://...:5432 start_momentry.sh +6379 redis redis-server REDIS_URL redis://...:6379 start_momentry.sh +6333 qdrant qdrant QDRANT_URL http://...:6333 start_momentry.sh +8081 wordpress Caddy - - Caddyfile +8082 llm llama-server MOMENTRY_LLM_CHAT_URL http://...:8082 start_momentry.sh +9000 php-fpm php-fpm - 9000 brew services +11434 ollama ollama MOMENTRY_OLLAMA_URL http://...:11434 start_momentry.sh +11436 embedding embeddinggemma MOMENTRY_EMBED_URL http://...:11436 start_momentry.sh diff --git a/src/api/health.rs b/src/api/health.rs index 547e468..4737133 100644 --- a/src/api/health.rs +++ b/src/api/health.rs @@ -375,9 +375,9 @@ async fn health_detailed(State(state): State) -> Json = Lazy::new(|| { pub static MONGODB_DATABASE: Lazy = Lazy::new(|| env::var("MONGODB_DATABASE").unwrap_or_else(|_| "momentry".to_string())); +pub static EMBED_URL: Lazy = + Lazy::new(|| env::var("MOMENTRY_EMBED_URL").unwrap_or_else(|_| "http://localhost:11436".to_string())); + +pub static OLLAMA_URL: Lazy = + Lazy::new(|| env::var("MOMENTRY_OLLAMA_URL").unwrap_or_else(|_| "http://localhost:11434".to_string())); + +/// LLM health endpoint derived from CHAT_URL. +/// e.g. "http://127.0.0.1:8082/v1/chat/completions" → "http://127.0.0.1:8082/health" +pub static LLM_HEALTH_URL: Lazy = Lazy::new(|| { + let chat = llm::CHAT_URL.clone(); + chat.trim_end_matches("/v1/chat/completions").to_string() + "/health" +}); + pub static QDRANT_COLLECTION: Lazy = Lazy::new(|| env::var("QDRANT_COLLECTION").unwrap_or_else(|_| "momentry_rule1".to_string())); @@ -234,15 +247,11 @@ pub mod llm { /// Vision LLM endpoint (frame analysis, OCR). Can be same as CHAT_URL or different. /// Default: falls back to CHAT_URL - pub static VISION_URL: Lazy = Lazy::new(|| { - env::var("MOMENTRY_LLM_VISION_URL") - .unwrap_or_else(|_| CHAT_URL.clone()) - }); + pub static VISION_URL: Lazy = + Lazy::new(|| env::var("MOMENTRY_LLM_VISION_URL").unwrap_or_else(|_| CHAT_URL.clone())); - pub static VISION_MODEL: Lazy = Lazy::new(|| { - env::var("MOMENTRY_LLM_VISION_MODEL") - .unwrap_or_else(|_| CHAT_MODEL.clone()) - }); + pub static VISION_MODEL: Lazy = + Lazy::new(|| env::var("MOMENTRY_LLM_VISION_MODEL").unwrap_or_else(|_| CHAT_MODEL.clone())); /// Text summary LLM endpoint (5W1H, story). Can be same as CHAT_URL or different. pub static SUMMARY_URL: Lazy = Lazy::new(|| { diff --git a/src/core/db/sync_db.rs b/src/core/db/sync_db.rs index c5485c6..bd33bb2 100644 --- a/src/core/db/sync_db.rs +++ b/src/core/db/sync_db.rs @@ -78,7 +78,7 @@ impl SyncDb { pub async fn embed_text(&self, text: &str) -> Result> { let client = reqwest::Client::new(); let response = client - .post("http://localhost:11434/api/embeddings") + .post(&format!("{}/api/embeddings", crate::core::config::OLLAMA_URL.as_str())) .json(&serde_json::json!({ "model": "all-minilm", "prompt": text,