From a126fe8d18d724151580f88102a7995e12b26069 Mon Sep 17 00:00:00 2001 From: oss-sync Date: Wed, 17 Jun 2026 01:24:49 +0000 Subject: [PATCH] sync: update from private repo (cae291d) --- scripts/server.sh | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/server.sh b/scripts/server.sh index 0063b4e..2ab51f1 100755 --- a/scripts/server.sh +++ b/scripts/server.sh @@ -52,6 +52,29 @@ if [[ -f "$PROJECT_DIR/.env" ]]; then unset _line _kv _key _val _envfile_set _q _esc fi +# Best-effort read of `server.port` from config.yaml (top-level `server:` block). +# Only used for the display / lsof fallback below; the app reads config itself. +read_config_port() { + local cfg="$PROJECT_DIR/config.yaml" + [[ -f "$cfg" ]] || return 1 + awk ' + /^[^[:space:]#]/ { in_server = ($1 == "server:") } + in_server && $1 == "port:" { gsub(/[^0-9]/, "", $2); if ($2 != "") { print $2; exit } } + ' "$cfg" +} + +# Port precedence mirrors the app: explicit PORT (shell env or .env) > server.port +# in config.yaml > built-in default (9876). +# +# Only forward PORT to the app when the operator set it explicitly. Otherwise we +# must NOT inject it, or it would override `server.port` from config.yaml (the +# app resolves PORT env > server.port > default). PORT below is for the startup +# message / lsof stray-kill / status only; it tracks the effective value so those +# stay accurate without changing what the app binds. +PORT_EXPLICIT="${PORT:-}" +if [[ -z "$PORT_EXPLICIT" ]]; then + PORT="$(read_config_port || true)" +fi PORT="${PORT:-9876}" cd "$PROJECT_DIR" @@ -105,7 +128,13 @@ do_start() { # To launch as a gateway: `AAO_MODE=gateway scripts/server.sh start` and # set `gateway.listen_port` in config.yaml (default 4000). dist/index.js # is preserved as a worker-mode shim for legacy paths. - PORT="$PORT" AAO_MODE="${AAO_MODE:-worker}" nohup node dist/main.js >> "$LOG_FILE" 2>&1 & + # Forward PORT only when explicitly set; otherwise let the app resolve + # server.port from config.yaml (passing PORT here would override it). + if [[ -n "$PORT_EXPLICIT" ]]; then + PORT="$PORT_EXPLICIT" AAO_MODE="${AAO_MODE:-worker}" nohup node dist/main.js >> "$LOG_FILE" 2>&1 & + else + AAO_MODE="${AAO_MODE:-worker}" nohup node dist/main.js >> "$LOG_FILE" 2>&1 & + fi local pid=$! echo "$pid" > "$PID_FILE"