chore: 统一开发服务器端口为 13098

- 更新 .env.example、env.ts、vite.config.ts 默认端口
- 同步更新 sidecar.rs Rust 端口常量
- 更新 README、AGENTS.md 等文档中的端口引用
This commit is contained in:
2026-01-27 11:10:21 +08:00
parent d22a0f8d69
commit f2db4bff9d
7 changed files with 24 additions and 23 deletions

View File

@@ -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
# 不要更改

View File

@@ -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 数据库管理界面
```

View File

@@ -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 <PID>

View File

@@ -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<Option<CommandChild>>);
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. **日志**: 使用表情符号 (✓/✗/🔧/🚀) 和中文消息提供清晰的状态反馈

View File

@@ -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()

View File

@@ -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: {

View File

@@ -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 开发工具共用终端