diff --git a/dashboard/server.py b/dashboard/server.py index c2df3955..1ad715c7 100644 --- a/dashboard/server.py +++ b/dashboard/server.py @@ -34,6 +34,7 @@ OCLAW_HOME = pathlib.Path.home() / '.openclaw' MAX_REQUEST_BODY = 1 * 1024 * 1024 # 1 MB ALLOWED_ORIGIN = None # Set via --cors; None means restrict to localhost +_DASHBOARD_PORT = 7891 # Updated at startup from --port arg _DEFAULT_ORIGINS = { 'http://127.0.0.1:7891', 'http://localhost:7891', 'http://127.0.0.1:5173', 'http://localhost:5173', # Vite dev server @@ -71,7 +72,7 @@ def cors_headers(h): elif req_origin in _DEFAULT_ORIGINS: origin = req_origin else: - origin = 'http://127.0.0.1:7891' + origin = f'http://127.0.0.1:{_DASHBOARD_PORT}' h.send_header('Access-Control-Allow-Origin', origin) h.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') h.send_header('Access-Control-Allow-Headers', 'Content-Type') @@ -2534,8 +2535,12 @@ def main(): parser.add_argument('--cors', default=None, help='Allowed CORS origin (default: reflect request Origin header)') args = parser.parse_args() - global ALLOWED_ORIGIN + global ALLOWED_ORIGIN, _DASHBOARD_PORT, _DEFAULT_ORIGINS ALLOWED_ORIGIN = args.cors + _DASHBOARD_PORT = args.port + _DEFAULT_ORIGINS = _DEFAULT_ORIGINS | { + f'http://127.0.0.1:{args.port}', f'http://localhost:{args.port}', + } server = HTTPServer((args.host, args.port), Handler) log.info(f'三省六部看板启动 → http://{args.host}:{args.port}') diff --git a/scripts/run_loop.sh b/scripts/run_loop.sh index 57c71685..df317f61 100755 --- a/scripts/run_loop.sh +++ b/scripts/run_loop.sh @@ -42,6 +42,7 @@ rotate_log() { SCAN_INTERVAL="${2:-120}" # 巡检间隔(秒), 默认 120 SCAN_COUNTER=0 SCRIPT_TIMEOUT=30 # 单个脚本最大执行时间(秒) +DASHBOARD_PORT="${EDICT_DASHBOARD_PORT:-7891}" # 看板端口,可通过环境变量覆盖 echo "🏛️ 三省六部数据刷新循环启动 (PID=$$)" echo " 脚本目录: $SCRIPT_DIR" @@ -79,7 +80,7 @@ while true; do SCAN_COUNTER=$((SCAN_COUNTER + INTERVAL)) if (( SCAN_COUNTER >= SCAN_INTERVAL )); then SCAN_COUNTER=0 - curl -s -X POST http://127.0.0.1:7891/api/scheduler-scan \ + curl -s -X POST "http://127.0.0.1:${DASHBOARD_PORT}/api/scheduler-scan" \ -H 'Content-Type: application/json' -d '{"thresholdSec":180}' >> "$LOG" 2>&1 || true fi