LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
feat: allow configurable server bind host
nash_sufda0cae44fec
diff --git a/src-tauri/src/api_server.rs b/src-tauri/src/api_server.rsindex 90f74005..05268610 100644--- a/src-tauri/src/api_server.rs+++ b/src-tauri/src/api_server.rs@@ -14,7 +14,7 @@ use tiny_http::{Header, Method, Response, Server, StatusCode};use walkdir::WalkDir;use crate::cors::{local_cors_headers, request_origin};-use crate::{clip_server, commands};+use crate::{clip_server, commands, server_bind};const PORT: u16 = 19828;const API_PREFIX: &str = "/api/v1";@@ -74,7 +74,8 @@ pub fn start_api_server(app: AppHandle) {};API_STATUS.store(1, Ordering::Relaxed);- eprintln!("[API Server] Listening on http://127.0.0.1:{PORT}{API_PREFIX}");+ let addr = server_bind::bind_addr(&server_bind::configured_bind_host(), PORT);+ eprintln!("[API Server] Listening on http://{addr}{API_PREFIX}");for request in server.incoming_requests() {let method = request.method().clone();@@ -107,12 +108,14 @@ pub fn start_api_server(app: AppHandle) {}fn bind_server_with_retry() -> Option<Server> {+ let host = server_bind::configured_bind_host();+ let addr = server_bind::bind_addr(&host, PORT);for attempt in 1..=MAX_BIND_RETRIES {- match Server::http(format!("127.0.0.1:{PORT}")) {+ match Server::http(&addr) {Ok(server) => return Some(server),Err(err) => {eprintln!(- "[API Server] Failed to bind 127.0.0.1:{PORT} (attempt {attempt}/{MAX_BIND_RETRIES}): {err}"+ "[API Server] Failed to bind {addr} (attempt {attempt}/{MAX_BIND_RETRIES}): {err}");if attempt < MAX_BIND_RETRIES {thread::sleep(Duration::from_secs(BIND_RETRY_DELAY_SECS));diff --git a/src-tauri/src/clip_server.rs b/src-tauri/src/clip_server.rsindex 17a9ceab..9a861dec 100644--- a/src-tauri/src/clip_server.rs+++ b/src-tauri/src/clip_server.rs@@ -4,6 +4,7 @@ use std::thread;use tiny_http::{Header, Method, Response, Server};use crate::cors::{local_cors_headers, request_origin};+use crate::server_bind;static CURRENT_PROJECT: Mutex<String> = Mutex::new(String::new());static ALL_PROJECTS: Mutex<Vec<(String, String)>> = Mutex::new(Vec::new()); // (name, path)@@ -49,10 +50,12 @@ pub fn start_clip_server() {loop {// Try to bind the port with retrieslet server = {+ let host = server_bind::configured_bind_host();+ let addr = server_bind::bind_addr(&host, PORT);let mut last_err = String::new();let mut bound = None;for attempt in 1..=MAX_BIND_RETRIES {- match Server::http(format!("127.0.0.1:{}", PORT)) {+ match Server::http(&addr) {Ok(s) => {bound = Some(s);break;@@ -60,8 +63,8 @@ pub fn start_clip_server() {Err(e) => {last_err = format!("{}", e);eprintln!(- "[Clip Server] Bind attempt {}/{} failed: {}",- attempt, MAX_BIND_RETRIES, e+ "[Clip Server] Bind attempt {}/{} failed for {}: {}",+ attempt, MAX_BIND_RETRIES, addr, e);if attempt < MAX_BIND_RETRIES {thread::sleep(std::time::Duration::from_secs(@@ -75,8 +78,8 @@ pub fn start_clip_server() {Some(s) => s,None => {eprintln!(- "[Clip Server] Port {} unavailable after {} attempts: {}",- PORT, MAX_BIND_RETRIES, last_err+ "[Clip Server] Address {} unavailable after {} attempts: {}",+ addr, MAX_BIND_RETRIES, last_err);DAEMON_STATUS.store(2, Ordering::Relaxed); // port_conflictreturn; // Don't retry on port conflict — needs user action@@ -86,7 +89,8 @@ pub fn start_clip_server() {DAEMON_STATUS.store(1, Ordering::Relaxed); // runningrestart_count = 0; // Reset on successful bind- println!("[Clip Server] Listening on http://127.0.0.1:{}", PORT);+ let addr = server_bind::bind_addr(&server_bind::configured_bind_host(), PORT);+ println!("[Clip Server] Listening on http://{}", addr);for mut request in server.incoming_requests() {let origin = request_origin(&request);diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 112d99ac..eae28351 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -4,6 +4,7 @@ mod commands;mod cors;mod panic_guard;mod proxy;+mod server_bind;mod tray;mod types;diff --git a/src-tauri/src/server_bind.rs b/src-tauri/src/server_bind.rsnew file mode 100644index 00000000..7fab7df7--- /dev/null+++ b/src-tauri/src/server_bind.rs@@ -0,0 +1,63 @@+const DEFAULT_BIND_HOST: &str = "127.0.0.1";+const BIND_HOST_ENV: &str = "LLM_WIKI_BIND_HOST";++pub fn configured_bind_host() -> String {+ std::env::var(BIND_HOST_ENV)+ .ok()+ .and_then(|value| sanitize_bind_host(&value))+ .unwrap_or_else(|| DEFAULT_BIND_HOST.to_string())+}++pub fn bind_addr(host: &str, port: u16) -> String {+ if host.contains(':') && !host.starts_with('[') {+ format!("[{host}]:{port}")+ } else {+ format!("{host}:{port}")+ }+}++fn sanitize_bind_host(value: &str) -> Option<String> {+ let host = value.trim();+ if host.is_empty() {+ return None;+ }+ let valid = host+ .chars()+ .all(|ch| ch.is_ascii_alphanumeric() || matches!(ch, '.' | '-' | '_' | ':' | '[' | ']'));+ if valid {+ Some(host.to_string())+ } else {+ None+ }+}++#[cfg(test)]+mod tests {+ use super::{bind_addr, sanitize_bind_host};++ #[test]+ fn sanitize_bind_host_accepts_common_lan_hosts() {+ assert_eq!(sanitize_bind_host("0.0.0.0"), Some("0.0.0.0".to_string()));+ assert_eq!(+ sanitize_bind_host(" 192.168.1.10 "),+ Some("192.168.1.10".to_string())+ );+ assert_eq!(sanitize_bind_host("::1"), Some("::1".to_string()));+ assert_eq!(sanitize_bind_host("[::]"), Some("[::]".to_string()));+ }++ #[test]+ fn sanitize_bind_host_rejects_empty_or_address_injection() {+ assert_eq!(sanitize_bind_host(""), None);+ assert_eq!(sanitize_bind_host("0.0.0.0:19828/path"), None);+ assert_eq!(sanitize_bind_host("127.0.0.1;rm"), None);+ }++ #[test]+ fn bind_addr_wraps_unbracketed_ipv6_hosts() {+ assert_eq!(bind_addr("127.0.0.1", 19828), "127.0.0.1:19828");+ assert_eq!(bind_addr("0.0.0.0", 19828), "0.0.0.0:19828");+ assert_eq!(bind_addr("::1", 19828), "[::1]:19828");+ assert_eq!(bind_addr("[::]", 19828), "[::]:19828");+ }+}