From 88c37408e8833c492685ddb94fc882acd58b63a8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Mar 2026 09:43:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8C=96=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 3 +++ server/index.js | 3 +++ server/routes.js | 9 ++++++++- start.sh | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 run.sh diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..96d07f1 --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd /www/wwwroot/www.airtep.com2/usa +git fetch origin && git reset --hard origin/master && npm run build && pm2 restart 3 \ No newline at end of file diff --git a/server/index.js b/server/index.js index b03bd1f..168b2a1 100644 --- a/server/index.js +++ b/server/index.js @@ -64,6 +64,9 @@ function broadcastSituation() { } catch (_) {} } app.set('broadcastSituation', broadcastSituation) +if (typeof routes.setBroadcastSituation === 'function') { + routes.setBroadcastSituation(broadcastSituation) +} setInterval(broadcastSituation, 3000) // 供爬虫调用:先从磁盘重载 DB(纳入爬虫写入),再更新 updated_at 并立即广播 diff --git a/server/routes.js b/server/routes.js index 4a3ef93..2624113 100644 --- a/server/routes.js +++ b/server/routes.js @@ -5,6 +5,13 @@ const db = require('./db') const router = express.Router() +/** 由 index.js 注入,确保修订后能触发 WebSocket 广播(不依赖 req.app) */ +let _broadcastSituation = null +function setBroadcastSituation(fn) { + _broadcastSituation = typeof fn === 'function' ? fn : null +} +router.setBroadcastSituation = setBroadcastSituation + // 简单鉴权:通过环境变量配置的 API_ADMIN_KEY 保护敏感接口(不返回真实密钥) const ADMIN_API_KEY = process.env.API_ADMIN_KEY || '' @@ -202,7 +209,7 @@ router.get('/events', (req, res) => { // ---------- 手动修正看板数据(编辑页用) ---------- function broadcastAfterEdit(req) { try { - const broadcast = req.app?.get?.('broadcastSituation') + const broadcast = _broadcastSituation || req.app?.get?.('broadcastSituation') if (typeof broadcast === 'function') broadcast() } catch (_) {} } diff --git a/start.sh b/start.sh index 88403ea..63749bc 100755 --- a/start.sh +++ b/start.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash # 一键启动 US-Iran 态势面板:API + 前端 + 爬虫服务 set -e +# 使用 UTF-8,便于终端输入/显示中文 +export LANG="${LANG:-en_US.UTF-8}" +export LC_ALL="${LC_ALL:-en_US.UTF-8}" cd "$(dirname "$0")" # 若存在 .env 则加载(可在此设置 DASHSCOPE_API_KEY=sk-xxx,勿提交 .env)