From 5d398d0a299f56cafdb8546b023ec994d928035e Mon Sep 17 00:00:00 2001 From: panFD Date: Sat, 3 Oct 2026 15:37:24 +0800 Subject: [PATCH] =?UTF-8?q?chore(server):=20=E6=B7=BB=E5=8A=A0=20HOST=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81=E5=AE=B9=E5=99=A8=E9=83=A8?= =?UTF-8?q?=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在示例环境配置、README 和服务代码中添加 HOST 配置项,默认监听 0.0.0.0 以适配容器和局域网部署场景,同时更新服务启动日志显示正确的监听地址。 --- put/README.md | 1 + put/server/.env.example | 2 ++ put/server/index.js | 6 ++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/put/README.md b/put/README.md index cb903a36..86f77fa4 100644 --- a/put/README.md +++ b/put/README.md @@ -77,6 +77,7 @@ cd web && npm ci && npm run dev # 前端 :4004(已代理 /api → :3001 | `MONGO_URL` | — | 必填,MongoDB 连接串 | | `MONGO_DB` | `heroconfig` | 库名 | | `PORT` | `3001` | 服务端口 | +| `HOST` | `0.0.0.0` | 监听地址;容器部署必须保持 0.0.0.0 并映射端口(如 `docker run -p 3001:3001`) | | `SCHEMA_VERSION` | `1` | 数据结构版本,破坏性变更时 +1 | 前端单独部署(不经 server 托管)时,`web/.env` 配 `VITE_API_BASE=http://:3001`。 diff --git a/put/server/.env.example b/put/server/.env.example index c7b9c6d0..62c8bdf3 100644 --- a/put/server/.env.example +++ b/put/server/.env.example @@ -12,6 +12,8 @@ MONGO_DB=heroconfig # ---- 服务端口 ---- PORT=3001 +# 监听地址:默认 0.0.0.0(容器/局域网部署必须);仅本机访问可改 127.0.0.1 +HOST=0.0.0.0 # ---- 数据结构版本 ---- # 英雄/底座结构有破坏性变更时 +1,并执行 npm run push-meta 推送到库中 diff --git a/put/server/index.js b/put/server/index.js index d0bc8ac4..5d17702d 100644 --- a/put/server/index.js +++ b/put/server/index.js @@ -544,6 +544,8 @@ app.post('/api/apply', (req, res) => { }) const PORT = Number(process.env.PORT || 3001) +// 默认监听所有网卡,保证容器/局域网端口映射可用;可用 HOST=127.0.0.1 限制为本机 +const HOST = process.env.HOST || '0.0.0.0' // 线上设计版:托管前端构建产物(web/dist),单个服务即可对外提供完整站点 if (MODE === 'remote') { @@ -554,6 +556,6 @@ if (MODE === 'remote') { } } -app.listen(PORT, () => { - console.log(`[hero-config-tool] mode=${MODE} schemaVersion=${SCHEMA_VERSION} listening http://localhost:${PORT}`) +app.listen(PORT, HOST, () => { + console.log(`[hero-config-tool] mode=${MODE} schemaVersion=${SCHEMA_VERSION} listening http://${HOST}:${PORT}`) })