develop
echo 3 months ago
parent 303f17ede3
commit a8e96c3bc0

@ -1,81 +0,0 @@
# 后端联调指南
## 环境与代理
- 前端目录:`frontend-vue`
- 开发代理:`frontend-vue/vite.config.ts:25-30` 将前端的 `/api` 代理到后端 `VITE_API_TARGET`
- 环境变量:
- `frontend-vue/.env.development` 示例:`VITE_API_TARGET=https://your-backend.example.com`
- 可选:`VITE_DEV_HOST`、`VITE_ALLOWED_HOSTS` 控制本地开发主机与允许的外网访问
- 启动与构建:
- 开发:`cd frontend-vue && npm i && npm run dev`
- 预览:`npm run preview`
## 鉴权与凭证
- 认证头:`Authorization: Bearer <token>`
- 前端存储:
- `localStorage` 键名:`cm_user`、`cm_token`
- 应用启动恢复:`frontend-vue/src/app/main.ts:10-12`
- 路由守卫:`frontend-vue/src/app/router/index.ts:23-30` 未登录重定向到登录页;基于 `meta.roles` 进行角色校验
## 关键接口规范
- 健康检查:`GET /v1/health`
- 登录:`POST /v1/user/login`
- 请求体:`{ username, password }`
- 响应体:`{ token, user: { username, role, email? } }`
- 注册:`POST /v1/user/register`
- 请求体:`{ username, email, password, fullName }`
- 响应体:`{ token?, user: { username, role, email? } }`
- 用户列表:`GET /api/v1/users`
- 响应体:`{ users: Array<{ username, role, email }> }` 或 `Array<{ username, role, email }>`
- 前端选择逻辑:仅匹配当前登录用户名;未匹配则显示错误提示
- 权限不足(例如操作员 403页面显示权限提示
- 角色值规范化:后端返回的 `role` 会统一转为小写并支持常见别名(如 `administrator`→`admin`、`ops`→`operator`
- 集群与节点:
- `GET /v1/clusters``[{ uuid, host, ip, count, health }]`
- `POST /v1/clusters`、`DELETE /v1/clusters/:id`、`POST /v1/clusters/:id/start|stop`
- `GET /v1/nodes?cluster=<uuid>``[{ name, ip, status, cpu, mem, updated }]`
- `POST /v1/nodes/:name/start|stop`、`DELETE /v1/nodes/:name`
- 指标:
- CPU 趋势:`GET /v1/metrics/cpu_trend?cluster=<uuid>` → `{ times: string[], values: number[] }`
- 内存使用:`GET /v1/metrics/memory_usage?cluster=<uuid>` → `{ used: number, free: number }`
- 诊断:
- 故障摘要:`GET /v1/faults/summary?node=<name>|cluster=<host>` → `{ code, time, scope }`
- AI 对话历史:`GET /v1/ai/history?sessionId=<id>` → `{ messages: Array<{ role, content, reasoning? }> }`
- AI 对话:`POST /v1/ai/chat` → `{ reply, reasoning? }`
## 前端数据绑定要点
- 个人主页:`frontend-vue/src/app/views/Profile.vue`
- 仅使用后端数据;加载中与错误态可视化
- 角色标签映射:`frontend-vue/src/app/constants/roles.ts`
- 角色来源:
- 登录/注册优先采用后端返回的 `user.role``role``frontend-vue/src/app/stores/auth.ts:55-72,74-91`
- 诊断页与导航:
- 路由授权:`diagnosis` 允许 `admin/operator``frontend-vue/src/app/router/index.ts:12`
- 侧边栏入口基于角色显示(`frontend-vue/src/app/components/Sidebar.vue:7`
## 联调步骤
- 设置 `VITE_API_TARGET` 指向后端地址,确保后端允许来自前端的 CORS 与 Host
- 启动前端后检查 `GET /v1/health` 返回正常
- 使用真实账号登录,确认:
- `GET /v1/user/me` 返回用户信息,个人主页字段显示为后端数据
- 侧边栏与页面访问受角色控制
- 仪表板与诊断页数据来自后端接口
- 常见问题:
- Token 无效或过期 → 返回 `401`,需要重新登录
- 代理失败 → 检查 `VITE_API_TARGET` 与后端协议/端口
- 外网访问本地开发 → 配置 `VITE_ALLOWED_HOSTS`,参考 `Cloudflare-Tunnel-Guide.md`
## 参考文件
- `frontend-vue/vite.config.ts`
- `frontend-vue/src/app/main.ts`
- `frontend-vue/src/app/router/index.ts`
- `frontend-vue/src/app/stores/auth.ts`
- `frontend-vue/src/app/views/Profile.vue`
- `frontend-vue/src/app/components/Sidebar.vue`
- `frontend-vue/src/app/constants/roles.ts`

@ -1,65 +0,0 @@
# Cloudflare Tunnel 跨网络访问教程(方案 B
## 适用场景
- 你与远程主机不在同一局域网,需要临时向公网暴露本地开发端口(前端 5173、后端 8000
- 仅用于演示和联调;生产请使用命名隧道、反向代理与严格鉴权
## 准备
- 平台WindowsPowerShell
- 目录:在项目根目录执行(已下载 `cloudflared.exe`
## 步骤一:下载 cloudflared已完成
- 命令(参考):
```
$ProgressPreference = 'SilentlyContinue'; \
$url = 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe'; \
$out = Join-Path (Get-Location) 'cloudflared.exe'; \
Invoke-WebRequest -Uri $url -OutFile $out; \
Write-Host "Downloaded: $out"
```
## 步骤二启动前端隧道Vite 5173
- 启动命令:
```
.\cloudflared.exe tunnel --protocol http2 --url http://localhost:5173
```
- 终端会打印一个临时域名(示例):
```
https://<随机>.trycloudflare.com
```
- 远程访问:在浏览器打开该域名即可访问你的前端页面
- 提示:保持命令行进程运行;若 HMR 异常,可在 `frontend-vue/.env` 设置:
```
VITE_HMR_HOST=<上述临时域名>
VITE_HMR_PORT=443
```
## 步骤三启动后端隧道API 8000
- 启动命令:
```
根目录执行
.\cloudflared.exe tunnel --protocol http2 --url http://localhost:8000 --no-autoupdate
```
- 终端会打印另一个临时域名;将前端代理目标指向该域名:
```
VITE_API_TARGET=https://<后端临时域名>
```
## 验证
- 前端:打开前端临时域名首页;访问 `/<任意页面>``/@vite/client`HMR 检测)
- 后端:访问 `https://<后端临时域名>/api/v1/health` 返回 200 即可
## 常见问题
- QUIC 连接超时:增加 `--protocol http2`(已使用)
- 日志提示未找到证书Quick Tunnel 可忽略;若使用命名隧道请按官方文档配置证书
- 端口未监听:确保本地 `npm run dev``uvicorn` 已启动5173、8000
## 安全与说明
- 临时域名仅用于演示Cloudflare 可能回收,随时重启生成新域名
- 不要在开发环境暴露敏感信息;生产务必启用 TLS 与鉴权,并限制来源
## 关闭隧道
- 在运行隧道的终端按 `Ctrl + C` 即可
## 参考
- 官方文档https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/run-tunnel/trycloudflare/

Binary file not shown.

@ -1,68 +0,0 @@
# Git 隐藏历史 (Reflog)
| 日期 | 版本 (Hash) | 操作/消息 |
| :--- | :--- | :--- |
| 2025-12-29 14:48:30 +0000 | `22e4772` | pull --rebase origin develop (finish): returning to refs/heads/develop |
| 2025-12-29 14:48:30 +0000 | `22e4772` | pull --rebase origin develop (pick): 集群注册_容器ssh连接问题修复 |
| 2025-12-29 14:48:30 +0000 | `f0fccd5` | pull --rebase origin develop (start): checkout f0fccd5c6083cd4dd5a433f4322b318874d3e02b |
| 2025-12-29 14:46:10 +0000 | `8bbf7bb` | commit: 集群注册_容器ssh连接问题修复 |
| 2025-12-29 13:32:14 +0000 | `742b1d0` | pull --rebase origin develop (finish): returning to refs/heads/develop |
| 2025-12-29 13:32:14 +0000 | `742b1d0` | pull --rebase origin develop (pick): 流式输出优化 |
| 2025-12-29 13:32:14 +0000 | `a570f82` | pull --rebase origin develop (start): checkout a570f82e9785853c862ed22bf7f6389d666865af |
| 2025-12-29 13:31:41 +0000 | `c6a821d` | commit: 流式输出优化 |
| 2025-12-29 13:13:50 +0000 | `d4c7cf8` | pull --rebase origin develop (finish): returning to refs/heads/develop |
| 2025-12-29 13:13:50 +0000 | `d4c7cf8` | pull --rebase origin develop (pick): ai聊天流式输出_后端 |
| 2025-12-29 13:13:50 +0000 | `630f637` | pull --rebase origin develop (start): checkout 630f6375f7967824dae3b1bd25b9148f83d79d5c |
| 2025-12-29 13:11:31 +0000 | `47be97e` | commit: ai聊天流式输出_后端 |
| 2025-12-29 11:40:41 +0000 | `a48ae19` | commit: ai联网搜索功能修复 |
| 2025-12-29 11:40:36 +0000 | `28381d4` | commit: ai联网搜索功能修复 |
| 2025-12-29 11:27:20 +0000 | `e3d18fa` | pull origin develop --rebase (finish): returning to refs/heads/develop |
| 2025-12-29 11:27:20 +0000 | `e3d18fa` | pull origin develop --rebase (pick): feat: add description field to cluster registration and fix 500 error |
| 2025-12-29 11:27:20 +0000 | `d52b431` | pull origin develop --rebase (start): checkout d52b431e259798a202afac720292fd4a60fc4e65 |
| 2025-12-29 11:27:19 +0000 | `ddacc09` | commit: feat: add description field to cluster registration and fix 500 error |
| 2025-12-29 11:25:01 +0000 | `b2524d6` | pull origin develop (finish): returning to refs/heads/develop |
| 2025-12-29 11:25:01 +0000 | `b2524d6` | pull origin develop (start): checkout b2524d6ce332061456112fe2e2c7dd57cc61aac6 |
| 2025-12-29 11:21:28 +0000 | `7e74e4d` | commit: 注册集群后端(无连接判断) |
| 2025-12-29 10:14:34 +0000 | `f62455b` | merge test_ai: Fast-forward |
| 2025-12-29 10:13:09 +0000 | `b49b2f7` | checkout: moving from test_ai to develop |
| 2025-12-29 10:10:02 +0000 | `f62455b` | pull origin develop (finish): returning to refs/heads/test_ai |
| 2025-12-29 10:10:02 +0000 | `f62455b` | pull origin develop (pick): ai功能修复_联网搜索工具 |
| 2025-12-29 10:10:02 +0000 | `3ae20a5` | pull origin develop (start): checkout 3ae20a5f67c847e6e3b497b95a09916d7472f946 |
| 2025-12-29 10:03:59 +0000 | `b688b37` | commit: ai功能修复_联网搜索工具 |
| 2025-12-29 09:19:26 +0000 | `b49b2f7` | reset: moving to b49b2f72de |
| 2025-12-29 09:04:27 +0000 | `b49b2f7` | reset: moving to b49b2f72de |
| 2025-12-29 09:03:35 +0000 | `7d7405f` | reset: moving to HEAD |
| 2025-12-29 08:40:31 +0000 | `7d7405f` | reset: moving to origin/develop |
| 2025-12-29 08:23:15 +0000 | `7d7405f` | pull origin develop: Fast-forward |
| 2025-12-29 07:48:15 +0000 | `90eaf53` | checkout: moving from develop to test_ai |
| 2025-12-29 07:46:18 +0000 | `b49b2f7` | commit: ai优化 |
| 2025-12-29 07:45:20 +0000 | `90eaf53` | checkout: moving from test_ai to develop |
| 2025-12-29 07:44:20 +0000 | `90eaf53` | checkout: moving from test_ai to test_ai |
| 2025-12-29 07:43:46 +0000 | `90eaf53` | checkout: moving from develop to test_ai |
| 2025-12-25 17:14:06 +0000 | `90eaf53` | checkout: moving from develop-backup to develop |
| 2025-12-25 17:13:44 +0000 | `90eaf53` | checkout: moving from develop to develop-backup |
| 2025-12-25 17:10:28 +0000 | `90eaf53` | reset: moving to 90eaf5395b |
| 2025-12-25 16:55:43 +0000 | `54393af` | reset: moving to origin/develop |
| 2025-12-25 16:37:03 +0000 | `54393af` | reset: moving to origin/develop |
| 2025-12-21 15:01:46 +0000 | `504a471` | commit: 小组周文档补 |
| 2025-12-21 14:06:56 +0000 | `cbc73bd` | commit: 李涛周文档补 |
| 2025-12-21 13:55:30 +0000 | `5d5b0e8` | pull origin develop (finish): returning to refs/heads/develop |
| 2025-12-21 13:55:30 +0000 | `5d5b0e8` | pull origin develop (pick): 沈永佳周文档 |
| 2025-12-21 13:55:30 +0000 | `33c7d27` | pull origin develop (start): checkout 33c7d27437f902238712c84d09c1c2fb94f9f419 |
| 2025-12-21 13:50:20 +0000 | `ef5314c` | commit: 沈永佳周文档 |
| 2025-12-19 08:37:11 +0000 | `f12e23e` | pull origin develop (finish): returning to refs/heads/develop |
| 2025-12-19 08:37:11 +0000 | `f12e23e` | pull origin develop (pick): users/me |
| 2025-12-19 08:37:11 +0000 | `19cca60` | pull origin develop (start): checkout 19cca60642d7ca9e8ae71081c27066940f2ab5fc |
| 2025-12-19 08:37:06 +0000 | `620afee` | commit: users/me |
| 2025-12-18 12:23:03 +0000 | `0842169` | commit: ai聊天架构优化 |
| 2025-12-18 07:45:08 +0000 | `eb935fa` | commit: 用户-角色映射优化 |
| 2025-12-18 07:08:52 +0000 | `2eb858a` | commit: chat前端联调指南 |
| 2025-12-18 05:26:53 +0000 | `2bda5cc` | pull origin develop: Fast-forward |
| 2025-12-14 15:54:36 +0000 | `bc65fec` | pull origin develop (finish): returning to refs/heads/develop |
| 2025-12-14 15:54:36 +0000 | `bc65fec` | pull origin develop (pick): 后端模型对话V1 |
| 2025-12-14 15:54:36 +0000 | `b6cb7a5` | pull origin develop (start): checkout b6cb7a58d8fbc92e26f6c69d441bbc6fba0880f7 |
| 2025-12-14 15:47:02 +0000 | `4796411` | commit: 后端模型对话V1 |
| 2025-12-14 08:02:42 +0000 | `15be5bb` | pull origin develop: Fast-forward |
| 2025-12-14 07:31:11 +0000 | `2f6fe59` | pull origin develop: Fast-forward |
| 2025-12-12 01:59:32 +0000 | `a7cdecc` | pull origin develop: Fast-forward |
| 2025-12-08 11:07:29 +0000 | `1533785` | clone: from https://bdgit.educoder.net/hnu202326010101/ErrorDetecting.git |
Loading…
Cancel
Save