A modern and elegant dashboard for network traffic visualization and analysis.
refactor: Simplify API URL resolution in frontend and clarify optional external exposure of API/WS ports in Docker.
luoleib756938a3c13
diff --git a/.env.example b/.env.exampleindex 6a385c9..71982db 100644--- a/.env.example+++ b/.env.example@@ -16,14 +16,16 @@# Web UI 访问端口 - 浏览器访问的地址 http://localhost:WEB_EXTERNAL_PORTWEB_EXTERNAL_PORT=3000-# API 端口 - 后端 API 服务端口+# API 端口(可选)- 仅直连/调试时需要+# 若仅通过 Nginx 反代 Web,前端会走 /api,无需对外开放 3001API_EXTERNAL_PORT=3001-# WebSocket 端口 - 实时数据传输端口+# WebSocket 端口(可选)- 实时数据推送+# 如需通过域名使用 WS,可在 Nginx 配置 /ws 代理并设置 WS_URLWS_EXTERNAL_PORT=3002# 说明:-# 上述外部端口会传入容器用于前端运行时配置。+# 只有当你需要“直连 API/WS”时才需要改这些外部端口。# 一般不需要修改容器内部端口(WEB_PORT/API_PORT/COLLECTOR_WS_PORT)。# -----------------------------------------------------------------------------diff --git a/README.en.md b/README.en.mdindex 4ffb06e..2b25545 100644--- a/README.en.md+++ b/README.en.md@@ -89,6 +89,19 @@ Open <http://localhost:3000> to get started.### Option 2: Docker Run+**Minimal (recommended, only Web exposed):**++```bash+docker run -d \+ --name clash-master \+ -p 3000:3000 \+ -v $(pwd)/data:/app/data \+ --restart unless-stopped \+ foru17/clash-master:latest+```++**Optional (only if you need direct API / WebSocket access):**+```bashdocker run -d \--name clash-master \@@ -102,6 +115,9 @@ docker run -d \Open <http://localhost:3000> to get started.+> The frontend uses same-origin `/api` by default, so only port 3000 is required.+> Only expose 3001/3002 if you need direct API/WS access or do not proxy `/api`/`/ws` in Nginx.+> If you use custom external ports with `docker run`, also pass:> `-e WEB_EXTERNAL_PORT=8080 -e API_EXTERNAL_PORT=8081 -e WS_EXTERNAL_PORT=8082`@@ -202,14 +218,14 @@ The script will automatically detect and suggest available ports.### Ports-| Port | Purpose | Required | Description |-| :--: | :-------: | :------: | :-------------------------- |-| 3000 | Web UI | ✅ | Frontend access port |-| 3001 | API | ✅ | REST API port |-| 3002 | WebSocket | ✅ | Real-time data transmission |+| Port | Purpose | External Required | Description |+| :--: | :-------: | :---------------: | :---------- |+| 3000 | Web UI | ✅ | Frontend entry point |+| 3001 | API | Optional | Only needed for direct access/debug; frontend uses `/api` by default |+| 3002 | WebSocket | Optional | Real-time updates; can be proxied via Nginx `/ws` |-> Recommended: change **external ports only** (`WEB_EXTERNAL_PORT / API_EXTERNAL_PORT / WS_EXTERNAL_PORT`)-> and keep internal ports at 3000/3001/3002. This avoids rebuilds and prevents `/api` 500 errors.+> You only need to reverse-proxy the Web UI in Nginx. The frontend uses same-origin `/api` by default,+> so 3001/3002 do not need to be exposed or configured unless you want direct API/WS access.### Multi-Architecture Supportdiff --git a/README.md b/README.mdindex 22a0e9e..d384945 100644--- a/README.md+++ b/README.md@@ -74,6 +74,20 @@ docker compose up -d### 方式二:Docker 直接运行+```bash+**最简(推荐,仅 Web 反代):**++```bash+docker run -d \+ --name clash-master \+ -p 3000:3000 \+ -v $(pwd)/data:/app/data \+ --restart unless-stopped \+ foru17/clash-master:latest+```++**可选(直连 API / WebSocket 时才需要):**+```bashdocker run -d \--name clash-master \@@ -85,6 +99,10 @@ docker run -d \foru17/clash-master:latest```+> 默认前端走同域 `/api`,所以只需要暴露 3000。+> 只有当你需要直连 API / WS 或未配置 Nginx `/api` / `/ws` 反代时,才需要暴露 3001/3002。+```+访问 <http://localhost:3000>> 如需自定义外部端口(docker run),请额外传入:@@ -187,14 +205,14 @@ curl -fsSL https://raw.githubusercontent.com/foru17/clash-master/main/setup.sh |### 端口说明-| 端口 | 用途 | 必需 | 说明 |-| :--: | :-------: | :--: | :------------ |-| 3000 | Web 界面 | ✅ | 前端访问端口 |-| 3001 | API 接口 | ✅ | REST API 端口 |-| 3002 | WebSocket | ✅ | 实时数据传输 |+| 端口 | 用途 | 外部必需 | 说明 |+| :--: | :-------: | :------: | :--- |+| 3000 | Web 界面 | ✅ | 前端访问入口 |+| 3001 | API 接口 | 可选 | 仅直连/调试时需要;前端默认走 `/api` |+| 3002 | WebSocket | 可选 | 实时数据推送;可通过 Nginx `/ws` 代理 |-> 建议只修改 **外部端口**(`WEB_EXTERNAL_PORT / API_EXTERNAL_PORT / WS_EXTERNAL_PORT`),-> 容器内部端口保持默认值(3000/3001/3002)。这样无需重新构建镜像,也不会出现 `/api` 500。+> 只配置主站 Web 的 Nginx 反代即可:前端默认同域访问 `/api`,无需额外暴露或配置 3001/3002。+> 如需直连 API/WS,可设置 `API_URL` / `WS_URL`,或暴露对应端口。### 多架构支持diff --git a/apps/web/lib/api.ts b/apps/web/lib/api.tsindex b050ad5..8cf6e9a 100644--- a/apps/web/lib/api.ts+++ b/apps/web/lib/api.ts@@ -13,8 +13,6 @@ import type {type RuntimeConfig = {API_URL?: string;- API_PORT?: string | number;- API_HOST?: string;};function getRuntimeConfig(): RuntimeConfig | undefined {@@ -33,11 +31,6 @@ function resolveApiBase(): string {if (runtime?.API_URL) {return normalizeApiBase(runtime.API_URL);}- if (runtime?.API_PORT && typeof window !== "undefined") {- const protocol = window.location.protocol;- const host = runtime.API_HOST || window.location.hostname;- return `${protocol}//${host}:${runtime.API_PORT}/api`;- }const envUrl = process.env.NEXT_PUBLIC_API_URL || process.env.API_URL;if (envUrl) {return normalizeApiBase(envUrl);