From d9eee5fd2db6545f8f1ffb2fe24ebe015102742a Mon Sep 17 00:00:00 2001 From: CJACK Date: Mon, 6 Apr 2026 00:13:22 +0800 Subject: [PATCH] docs: clarify server binding address and LAN accessibility in documentation and startup logs --- README.MD | 4 +++- README.en.md | 4 +++- docs/CONTRIBUTING.en.md | 3 ++- docs/CONTRIBUTING.md | 3 ++- start.mjs | 37 +++++++++++++++++++------------------ 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/README.MD b/README.MD index cf5f5c4..b2000d2 100644 --- a/README.MD +++ b/README.MD @@ -178,7 +178,9 @@ cp config.example.json config.json go run ./cmd/ds2api ``` -默认监听地址:`http://localhost:5001` +默认本地访问地址:`http://127.0.0.1:5001` + +服务实际绑定:`0.0.0.0:5001`,因此同一局域网设备通常也可以通过你的内网 IP 访问。 > **WebUI 自动构建**:本地首次启动时,若 `static/admin` 不存在,会自动尝试执行 `npm ci`(仅在缺少依赖时)和 `npm run build -- --outDir static/admin --emptyOutDir`(需要本机有 Node.js)。你也可以手动构建:`./scripts/build-webui.sh` diff --git a/README.en.md b/README.en.md index 106ebe2..d128320 100644 --- a/README.en.md +++ b/README.en.md @@ -178,7 +178,9 @@ cp config.example.json config.json go run ./cmd/ds2api ``` -Default URL: `http://localhost:5001` +Default local URL: `http://127.0.0.1:5001` + +The server actually binds to `0.0.0.0:5001`, so devices on the same LAN can usually reach it through your private IP as well. > **WebUI auto-build**: On first local startup, if `static/admin` is missing, DS2API will auto-run `npm ci` (only when dependencies are missing) and `npm run build -- --outDir static/admin --emptyOutDir` (requires Node.js). You can also build manually: `./scripts/build-webui.sh` diff --git a/docs/CONTRIBUTING.en.md b/docs/CONTRIBUTING.en.md index ad04e0e..0803703 100644 --- a/docs/CONTRIBUTING.en.md +++ b/docs/CONTRIBUTING.en.md @@ -25,7 +25,8 @@ cp config.example.json config.json # 3. Run backend go run ./cmd/ds2api -# Default: http://localhost:5001 +# Local access: http://127.0.0.1:5001 +# Actual bind: 0.0.0.0:5001, so LAN access is available via your private IP ``` ### Frontend Development (WebUI) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 0883df0..3a3a43b 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -25,7 +25,8 @@ cp config.example.json config.json # 3. 启动后端 go run ./cmd/ds2api -# 默认监听 http://localhost:5001 +# 本地访问 http://127.0.0.1:5001 +# 实际绑定 0.0.0.0:5001,可通过局域网 IP 访问 ``` ### 前端开发(WebUI) diff --git a/start.mjs b/start.mjs index d168be3..7f037be 100644 --- a/start.mjs +++ b/start.mjs @@ -264,10 +264,10 @@ async function buildWebui() { } // 启动后端(开发模式:go run,无需预编译) -async function startBackendDev() { - if (!checkGo()) throw new Error('未找到 Go,请先安装 Go (https://go.dev/dl/)'); - log.info(`启动后端(go run)... http://localhost:${CONFIG.port}`); - const proc = spawn('go', ['run', './cmd/ds2api'], { +async function startBackendDev() { + if (!checkGo()) throw new Error('未找到 Go,请先安装 Go (https://go.dev/dl/)'); + log.info(`启动后端(go run)... 本地 http://127.0.0.1:${CONFIG.port} 绑定 0.0.0.0:${CONFIG.port}`); + const proc = spawn('go', ['run', './cmd/ds2api'], { cwd: __dirname, stdio: 'inherit', shell: true, @@ -284,13 +284,13 @@ async function startBackendDev() { } // 启动后端(生产模式:运行编译好的二进制) -async function startBackendProd() { - if (!binaryExists()) { - log.warn('未找到编译产物,正在编译...'); - await buildBackend(); - } - log.info(`启动后端(二进制)... http://localhost:${CONFIG.port}`); - const proc = spawn(BINARY, [], { +async function startBackendProd() { + if (!binaryExists()) { + log.warn('未找到编译产物,正在编译...'); + await buildBackend(); + } + log.info(`启动后端(二进制)... 本地 http://127.0.0.1:${CONFIG.port} 绑定 0.0.0.0:${CONFIG.port}`); + const proc = spawn(BINARY, [], { cwd: __dirname, stdio: 'inherit', shell: false, @@ -323,13 +323,14 @@ async function startFrontend() { } // 显示状态信息 -function showStatus() { - console.log('\n' + '─'.repeat(50)); - log.success(`后端 API: http://localhost:${CONFIG.port}`); - log.success(`管理界面: http://localhost:${CONFIG.port}/admin`); - if (existsSync(CONFIG.webuiDir)) { - log.success(`前端 Dev: http://localhost:${CONFIG.frontendPort}`); - } +function showStatus() { + console.log('\n' + '─'.repeat(50)); + log.success(`后端 API: http://127.0.0.1:${CONFIG.port}`); + log.success(`管理界面: http://127.0.0.1:${CONFIG.port}/admin`); + log.info(`后端绑定: 0.0.0.0:${CONFIG.port} (可通过局域网 IP 访问)`); + if (existsSync(CONFIG.webuiDir)) { + log.success(`前端 Dev: http://localhost:${CONFIG.frontendPort}`); + } console.log('─'.repeat(50)); log.info('按 Ctrl+C 停止所有服务\n'); }