feat: expose boss via nginx base path

This commit is contained in:
Codex
2026-03-23 13:31:23 +08:00
parent bc04c439fb
commit 5c3636fe6a
9 changed files with 149 additions and 44 deletions

View File

@@ -7,4 +7,4 @@ export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}"
export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}"
"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); if sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then sudo docker compose -f compose.cloud.yaml -p boss ps; echo '---'; curl -fsS http://127.0.0.1:43210/api/health; else ./scripts/server_status.sh; fi"
"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); if sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then sudo docker compose -f compose.cloud.yaml -p boss ps; echo '---'; curl -fsS http://127.0.0.1:43210/boss/api/health; else BOSS_BASE_PATH=/boss ./scripts/server_status.sh; fi"

View File

@@ -45,11 +45,40 @@ if [[ "\$DEPLOY_MODE" != "node" ]]; then
fi
if [[ "\$docker_ok" -eq 1 ]]; then
sudo python3 - <<'PY'
from pathlib import Path
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
text = path.read_text()
if "location /boss/" not in text:
block = """
location = /boss {
return 302 /boss/;
}
location /boss/ {
proxy_pass http://127.0.0.1:43210;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_buffering off;
}
"""
marker = " location / {\n"
text = text.replace(marker, block + marker, 1)
path.write_text(text)
PY
sudo nginx -t
sudo systemctl reload nginx
echo "__BOSS_DEPLOY_OK__"
echo "mode=docker"
sudo docker compose -f compose.cloud.yaml -p boss ps
sleep 3
curl -fsS http://127.0.0.1:43210/api/health
curl -fsS http://127.0.0.1:43210/boss/api/health
exit 0
fi
@@ -60,10 +89,39 @@ fi
npm install
npm run build
PORT=43210 BOSS_DATA_FILE=.boss-data/cloud-store.json ./scripts/server_start.sh
PORT=43210 BOSS_DATA_FILE=.boss-data/cloud-store.json BOSS_BASE_PATH=/boss ./scripts/server_start.sh
sudo python3 - <<'PY'
from pathlib import Path
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
text = path.read_text()
if "location /boss/" not in text:
block = """
location = /boss {
return 302 /boss/;
}
location /boss/ {
proxy_pass http://127.0.0.1:43210;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_buffering off;
}
"""
marker = " location / {\n"
text = text.replace(marker, block + marker, 1)
path.write_text(text)
PY
sudo nginx -t
sudo systemctl reload nginx
echo "__BOSS_DEPLOY_OK__"
echo "mode=node"
./scripts/server_status.sh
BOSS_BASE_PATH=/boss ./scripts/server_status.sh
EOF
)

View File

@@ -6,6 +6,12 @@ data_dir="${BOSS_DATA_DIR:-.boss-data}"
data_file="${BOSS_DATA_FILE:-$data_dir/server-store.json}"
pid_file="${BOSS_PID_FILE:-$data_dir/server.pid}"
log_file="${BOSS_LOG_FILE:-$data_dir/server.log}"
base_path="${BOSS_BASE_PATH:-}"
if [[ -n "$base_path" && "$base_path" != /* ]]; then
base_path="/$base_path"
fi
base_path="${base_path%/}"
health_url="http://127.0.0.1:${port}${base_path}/api/health"
mkdir -p "$data_dir"
@@ -27,7 +33,7 @@ nohup env PORT="$port" BOSS_DATA_FILE="$data_file" node dist/server.js >>"$log_f
echo $! > "$pid_file"
for _ in {1..30}; do
if curl -fsS "http://127.0.0.1:${port}/api/health" >/dev/null 2>&1; then
if curl -fsS "$health_url" >/dev/null 2>&1; then
echo "Boss server started on :${port}"
exit 0
fi

View File

@@ -5,6 +5,12 @@ port="${PORT:-43210}"
data_dir="${BOSS_DATA_DIR:-.boss-data}"
pid_file="${BOSS_PID_FILE:-$data_dir/server.pid}"
log_file="${BOSS_LOG_FILE:-$data_dir/server.log}"
base_path="${BOSS_BASE_PATH:-}"
if [[ -n "$base_path" && "$base_path" != /* ]]; then
base_path="/$base_path"
fi
base_path="${base_path%/}"
health_url="http://127.0.0.1:${port}${base_path}/api/health"
if [[ -f "$pid_file" ]]; then
pid="$(cat "$pid_file")"
@@ -18,7 +24,7 @@ else
fi
echo "---"
curl -fsS "http://127.0.0.1:${port}/api/health" || true
curl -fsS "$health_url" || true
echo
echo "---"
tail -n 40 "$log_file" 2>/dev/null || true