From f2db4bff9df0d7823faef7856d504ac8a2b7f35f Mon Sep 17 00:00:00 2001 From: MAO Dongyang Date: Tue, 27 Jan 2026 11:10:21 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=BB=9F=E4=B8=80=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=AB=AF=E5=8F=A3=E4=B8=BA=2013098?= =?UTF-8?q?=20-=20=E6=9B=B4=E6=96=B0=20.env.example=E3=80=81env.ts?= =?UTF-8?q?=E3=80=81vite.config.ts=20=E9=BB=98=E8=AE=A4=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=20-=20=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=20sidecar.rs=20Rust?= =?UTF-8?q?=20=E7=AB=AF=E5=8F=A3=E5=B8=B8=E9=87=8F=20-=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20README=E3=80=81AGENTS.md=20=E7=AD=89=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=B8=AD=E7=9A=84=E7=AB=AF=E5=8F=A3=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 +++-- AGENTS.md | 2 +- README.md | 14 +++++++------- src-tauri/AGENTS.md | 12 ++++++------ src-tauri/src/sidecar.rs | 4 ++-- src/env.ts | 4 ++-- vite.config.ts | 6 +++--- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index 6679856..d93d474 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ -TOKEN_USAGE_URL=http://10.0.1.1:8318/usage -PROJECT_SERVER_PORT=3214 +TOKEN_USAGE_URL=http://10.0.1.1:8318/api/usage/model +PROJECT_SERVER_PORT=13098 +# 不要更改 \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md index cb9bb73..0208239 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,7 +21,7 @@ ### 开发 ```bash bun dev # 使用 Turbo 并行启动 Tauri + Vite 开发服务器 -bun dev:vite # 仅启动 Vite 开发服务器 (localhost:3000) +bun dev:vite # 仅启动 Vite 开发服务器 (localhost:13098) bun dev:tauri # 启动 Tauri 桌面应用 bun db:studio # 打开 Drizzle Studio 数据库管理界面 ``` diff --git a/README.md b/README.md index bd4fd69..7342c4f 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ cd openbridge-token-usage-viewer bun install # 3. 启动开发服务器 -bun run dev:vite # 仅 Web (http://localhost:3000) +bun run dev:vite # 仅 Web (http://localhost:13098) bun run dev # Tauri 桌面应用 + Web ``` @@ -126,7 +126,7 @@ TOKEN_USAGE_URL=http://your-server:8318/usage | 命令 | 说明 | |------|------| | `bun dev` | 启动 Tauri + Vite 开发服务器 (并行) | -| `bun dev:vite` | 仅启动 Vite 开发服务器 (http://localhost:3000) | +| `bun dev:vite` | 仅启动 Vite 开发服务器 (http://localhost:13098) | | `bun dev:tauri` | 仅启动 Tauri (需先启动 Vite) | | `bun db:studio` | 打开 Drizzle Studio 数据库管理界面 | @@ -229,7 +229,7 @@ const { data } = useSuspenseQuery(orpc.usage.getUsage.queryOptions()) 1. **Tauri 壳**: 提供原生窗口和系统集成 2. **Bun 服务端**: 编译为独立可执行文件,处理 SSR 和 API 请求 -3. **通信**: Tauri WebView 通过 localhost:3000 与 Sidecar 通信 +3. **通信**: Tauri WebView 通过 localhost:13098 与 Sidecar 通信 ### 数据流 @@ -295,10 +295,10 @@ rm -rf src-tauri/target ```bash # Windows -netstat -ano | findstr :3000 +netstat -ano | findstr :13098 # Linux/macOS -lsof -i :3000 +lsof -i :13098 ``` #### 5. 重新构建 @@ -311,7 +311,7 @@ bun run build #### "An unhandled error happened!" 错误 -1. 确保没有其他进程占用端口 3000 +1. 确保没有其他进程占用端口 13098 2. 尝试完全清理缓存后重新构建 3. 检查 `.env` 文件中的 `TOKEN_USAGE_URL` 配置是否正确 @@ -319,7 +319,7 @@ bun run build ```powershell # 查找占用端口的进程 -netstat -ano | findstr :3000 +netstat -ano | findstr :13098 # 结束进程 (替换 PID 为实际进程 ID) taskkill /F /PID diff --git a/src-tauri/AGENTS.md b/src-tauri/AGENTS.md index b4bbe0a..cae26f4 100644 --- a/src-tauri/AGENTS.md +++ b/src-tauri/AGENTS.md @@ -8,7 +8,7 @@ - **后端**: Rust (Edition 2021) - **架构**: Sidecar 模式 - Sidecar App 承载主要业务逻辑 - **设计理念**: Tauri 仅提供原生桌面能力(文件对话框、系统通知等),Web 逻辑全部由 Sidecar App 处理 -- **开发模式**: 使用 localhost:3000(需手动启动开发服务器) +- **开发模式**: 使用 localhost:13098(需手动启动开发服务器) - **生产模式**: 自动启动 Sidecar 二进制 - **异步运行时**: Tokio - **Rust 版本**: 1.92.0+ @@ -30,7 +30,7 @@ bun run dev:tauri ``` **开发模式说明**: -- 开发模式下,Tauri 直接连接到 `localhost:3000`(不启动 sidecar 二进制) +- 开发模式下,Tauri 直接连接到 `localhost:13098`(不启动 sidecar 二进制) - 需要手动运行 `bun run dev` 来启动开发服务器 - 支持热重载(HMR),无需重启 Tauri 应用 @@ -141,12 +141,12 @@ use tauri::*; ```rust // ✅ 推荐 struct SidecarProcess(Mutex>); -const DEFAULT_PORT: u16 = 3000; +const DEFAULT_PORT: u16 = 13098; async fn find_available_port(start: u16) -> u16 { } // ❌ 避免 struct sidecar_process { } -const defaultPort: u16 = 3000; +const defaultPort: u16 = 13098; ``` ### 类型注解 @@ -205,7 +205,7 @@ let data = read_file().unwrap(); // 无上下文信息 ```rust // ✅ 推荐 tauri::async_runtime::spawn(async move { - let port = find_available_port(3000).await; + let port = find_available_port(13098).await; // ... }); ``` @@ -339,7 +339,7 @@ tokio = { version = "1", features = ["net"] } - 生产构建自动打包 sidecar 二进制,无需额外配置 2. **进程生命周期**: 始终在应用退出时清理子进程和资源 3. **端口管理**: - - 开发模式固定使用 3000 端口(与开发服务器匹配) + - 开发模式固定使用 13098 端口(与开发服务器匹配) - 生产模式使用端口扫描避免硬编码端口冲突 4. **超时处理**: 异步操作设置合理的超时时间 (如 5 秒) 5. **日志**: 使用表情符号 (✓/✗/🔧/🚀) 和中文消息提供清晰的状态反馈 diff --git a/src-tauri/src/sidecar.rs b/src-tauri/src/sidecar.rs index fa3d9d7..0577a53 100644 --- a/src-tauri/src/sidecar.rs +++ b/src-tauri/src/sidecar.rs @@ -11,9 +11,9 @@ use tauri_plugin_shell::ShellExt; const SIDECAR_NAME: &str = "openbridgeTokenUsageViewerServer"; /// 默认服务器端口 -const DEFAULT_PORT: u16 = 3000; +const DEFAULT_PORT: u16 = 13098; -/// 从环境变量获取端口 (PROJECT_SERVER_PORT),默认 3000 +/// 从环境变量获取端口 (PROJECT_SERVER_PORT),默认 13098 fn get_project_port() -> u16 { std::env::var("PROJECT_SERVER_PORT") .ok() diff --git a/src/env.ts b/src/env.ts index 636cd6d..dc4c3bf 100644 --- a/src/env.ts +++ b/src/env.ts @@ -13,7 +13,7 @@ import { z } from 'zod' const DEFAULT_TOKEN_USAGE_URL = 'http://10.0.1.1:8318/api/usage/model' /** 服务器端口默认值 */ -const DEFAULT_SERVER_PORT = '3000' +const DEFAULT_SERVER_PORT = '13098' /** * 判断当前是否为打包后的可执行文件运行环境 @@ -134,7 +134,7 @@ export const env = createEnv({ .int() .min(1) .max(65535) - .default(3000), + .default(13098), }, clientPrefix: 'VITE_', client: { diff --git a/vite.config.ts b/vite.config.ts index a077c0e..4b5818f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,7 @@ * - Bun 运行时优化 (nitro preset: 'bun') * - 静态资源内联 (serveStatic: 'inline') * - React Compiler 自动优化 (无需手动 memo) - * - 端口从环境变量 PROJECT_SERVER_PORT 读取 (默认 3000) + * - 端口默认 13098 */ import tailwindcss from '@tailwindcss/vite' import { devtools as tanstackDevtools } from '@tanstack/devtools-vite' @@ -24,8 +24,8 @@ import tsconfigPaths from 'vite-tsconfig-paths' /** 加载 .env 文件中的环境变量 */ const envVars = loadEnv('development', process.cwd(), '') -/** 开发服务器端口 (从环境变量读取,默认 3000) */ -const DEV_PORT = Number(envVars.PROJECT_SERVER_PORT) || 3000 +/** 开发服务器端口 (从环境变量读取,默认 13098) */ +const DEV_PORT = 13098 export default defineConfig({ // 禁止清屏,方便与 Tauri 开发工具共用终端