fix: 修复桌面版配置请求网络错误

This commit is contained in:
2026-05-20 15:16:48 +08:00
parent 2cdc0a0c81
commit 22c343a85e
9 changed files with 21 additions and 9 deletions
+1
View File
@@ -151,6 +151,7 @@ dist\desktop\*-setup.exe
桌面版使用 Tauri 启动 Python sidecar。sidecar 默认监听 `127.0.0.1:19082`,运行数据写入系统 app data 目录,不写入安装目录。
首次启动会把安装包内置的 `Configure.json` 和 `ReportScript.sql` 复制到运行数据目录;Windows 下通常是 `%APPDATA%\com.nixevol.capacityreport\`。安装目录中的 `_up_` 只是 Tauri 打包资源目录,程序运行时不会直接编辑它。
Windows 桌面版使用 NSIS 安装器,卸载时会询问是否同时删除 `%APPDATA%\com.nixevol.capacityreport\` 中的配置、脚本、授权、缓存和日志。
桌面版 release 包已启用 DevTools,如需排查前端请求,可在窗口中按 `F12` 或右键打开开发者工具。
构建桌面版需要 Rust 和 Tauri CLI。脚本会在缺少 Tauri CLI 时自动执行:
+1 -1
View File
@@ -32,7 +32,7 @@ async def health_check():
return {
"status": "healthy" if is_healthy else "unhealthy",
"timestamp": datetime.now().isoformat(),
"version": "2.0.2",
"version": "2.0.3",
"uptime_pid": os.getpid(),
"checks": checks,
}
+1 -1
View File
@@ -54,7 +54,7 @@ async def restart_service():
async def get_service_status():
return {
"status": "running",
"version": "2.0.2",
"version": "2.0.3",
"platform": platform.system(),
"supervisor": is_supervisor_running(),
"container": is_container_runtime(),
+4 -1
View File
@@ -12,7 +12,7 @@ from app.auth import verify_jwt_token
from app.config import BASE_DIR
APP_VERSION = "2.0.2"
APP_VERSION = "2.0.3"
APP_HOST = "0.0.0.0"
APP_PORT = 9081
FRONTEND_DIST_DIR = BASE_DIR / "frontend" / "dist"
@@ -43,6 +43,9 @@ def create_app() -> FastAPI:
async def jwt_middleware(request: Request, call_next):
if request.method == "OPTIONS":
return await call_next(request)
path = request.url.path
if path.startswith("/api/") and path != "/api/login":
auth_header = request.headers.get("Authorization")
+7
View File
@@ -1,4 +1,11 @@
# 项目上下文记录
## 2026-05-20:修复桌面版跨源预检导致配置网络错误
- 桌面版前端访问 `127.0.0.1:19082` 属于 WebView 跨源请求,带 `Authorization` 或上传配置文件时浏览器会先发 `OPTIONS` 预检;`app/main.py` 的 JWT 中间件现在直接放行 `OPTIONS`,让 FastAPI CORS 中间件返回允许头,避免配置读取和配置上传显示“网络错误”。
- 桌面版版本提升为 `2.0.3`,同步更新 `app/main.py`、健康检查、服务状态、Tauri 配置、Cargo 包版本和侧边栏版本号,避免同版本安装包覆盖时难以确认是否装到新包。
- `src-tauri/Cargo.toml` 启用 Tauri `devtools` feature,`tauri.conf.json` 主窗口设置 `devtools: true`;Windows release 桌面包可按 `F12` 或右键打开开发者工具排查真实请求。
- 已用真实 uvicorn 服务验证 `Origin: http://tauri.localhost` 下 `/api/config/full` 和 `/api/config/upload` 的 `OPTIONS` 预检均返回 200,并且登录后 `/api/config/full` 可正常返回;随后执行 `scripts\build.bat desktop` 生成 `dist\desktop\CapacityReport_2.0.3_x64-setup.exe`,静默安装启动后验证 `/health` 返回 `2.0.3`、配置读取正常、脚本读取正常、配置上传返回 200。
## 2026-05-20:修复桌面版残留 sidecar 和卸载用户数据选择
- `src-tauri/src/main.rs` 启动 sidecar 前会先清理占用 `19082` 的旧 `capareport-server` 监听进程,避免卸载/重装或异常退出后连到旧服务;启动后不只检查端口可连接,还会请求 `/health` 返回 HTTP 200 才继续。
+1 -1
View File
@@ -25,7 +25,7 @@
<div class="sider-footer">
<span class="sider-version">
<span class="sider-version-label">版本:</span>
<span class="sider-version-number">v2.0.2</span>
<span class="sider-version-number">v2.0.3</span>
</span>
<span class="sider-powered">Power by:NIXEVOL</span>
</div>
+1 -1
View File
@@ -235,7 +235,7 @@ dependencies = [
[[package]]
name = "capacity-report-desktop"
version = "2.0.2"
version = "2.0.3"
dependencies = [
"tauri",
"tauri-build",
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "capacity-report-desktop"
version = "2.0.2"
version = "2.0.3"
description = "CapacityReport desktop shell"
authors = ["NIXEVOL"]
edition = "2021"
@@ -9,7 +9,7 @@ edition = "2021"
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri = { version = "2", features = ["devtools"] }
tauri-plugin-shell = "2"
[features]
+3 -2
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "CapacityReport",
"version": "2.0.2",
"version": "2.0.3",
"identifier": "com.nixevol.capacityreport",
"build": {
"frontendDist": "../frontend/dist"
@@ -14,7 +14,8 @@
"width": 1280,
"height": 820,
"minWidth": 1100,
"minHeight": 720
"minHeight": 720,
"devtools": true
}
],
"security": {