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}`) })