Files
2026-08-13 22:00:04 +08:00

109 lines
5.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 工作日志 2026-08-12
## 主题:cc-square 去 Spring Boot 化 —— Node 轻服务 + Redis 点击计数(已上线)
### 背景 / 起因
- VPS 内存紧张,需放弃部署重型的 Spring Boot 后端(yudao/ruoyi-vue-pro
- 前端需改造为"独立查询数据"形式
- 书签排序需要"访问次数"记录
### 关键决策(用户确认)
1. 点击次数**只存 Redis**,不落 MySQL
2. Redis 启用持久化(VPS Redis 已支持 AOF
3. 排序规则:**纯点击倒序**ZREVRANGE
4. Node 服务部署在 VPS
5. 前端 baseUrl 走 nginx `/api` 反代(rewrite 剥 /api → 48080
6. 彻底清理前端鉴权(方案 B:删 token/login/userInfo/auth.js/qs
### 最终架构(已上线)
```
浏览器 → https://www.climbcube.cnnginx 托管前端 dist
└→ /api/tab/* → nginx(rewrite剥/api) → Node(Express, 48080) → MySQL(只读) + Redis(点击/排序)
```
### 连接凭据(已验证)
- 公网 MySQL`101.34.227.188:3306`readonly,密码 135246host `%`(任意来源)
- 公网 Redis`101.34.227.188:6379`,密码 5gynj20JAOF 持久化
- MySQL 数据:cc_website 212行(启用124)/cc_engine 23行/cc_website_type 11行
- 字段细节:cc_website_type 分类名是 **title** 列(非 name),有 ordercc_engine 无 order 列,仅按 click 排序
### 交付物(/home/yangxuan/cc-square/server/
| 文件 | 说明 |
|------|------|
| server.js | 主程序:静态托管 + /tab/* 接口 + Redis 计数/排序 |
| config.js | 配置(支持环境变量,不入 git)|
| scripts/init-redis.js | Redis 历史点击导入(幂等)|
| ecosystem.config.js | pm2 配置 |
| package.json | 依赖 express/mysql2/redis/axios |
| .env.example / .env | 环境变量模板 / 实际密码(.env 不入 git|
| DEPLOY.md | 部署文档(含完整 pm2 命令:日志/状态/启停/开机自启)|
| FRONTEND-CHANGES.md | 前端改造说明 |
| README.md | 服务导航 |
### 接口(全部实测 200
| 方法 | 路径 | 数据源 |
|------|------|--------|
| GET | /tab/engine | MySQL cc_engine |
| GET | /tab/bookmark | MySQL 聚合(排除 nav-left,字段 website|
| GET | /tab/menu | MySQL |
| GET | /tab/quick?limit=N | Redis ZREVRANGE 点击排行 |
| GET | /tab/list-by-type?typeId=N | MySQL |
| GET | /tab/searchBookmark?keyword=x | MySQL |
| GET | /tab/weather/all | 高德API(未配 key 返回空降级)|
| POST | /tab/quickCount | Redis ZINCRBY(书签)|
| POST | /tab/engineCount | Redis ZINCRBY(引擎)|
| GET | /health | 健康检查 |
### 前端改造(已完成并 build)
1. `src/config/env.js`baseUrl 固定 `/api`
2. `src/request/http.js`:重写精简版(去 token/key 认证,保留 code===0
3. `src/request/api/nav.js``/app-api/tab/``/tab/`
4. `vite.config.js`dev 代理 `/api` → 本机 48080rewrite 剥 /api
5. **方案 B 清理鉴权**:删 auth.js、store 的 token/userInfo/setToken/clearAuth/logout、website.js 的 token/info key、util 的 info 残留、Search.js 登录判断改"添加引擎"提示、package.json 移除 qs
- 构建成功,dist 无鉴权代码,主 JS 变小(index 5.92→5.64kB
### bookmark 字段修复(重要)
- 前端 Bookmark/index.vue 渲染 `item.website`,初版 Node 返回 `list` → 书签不展示
- 修复:server.js bookmark 接口 `list``website`
- 并排除 nav-leftand yudao 原逻辑:title!='nav-left' and status=0),只保留有书签的分类
### 部署状态(已完成,生产生效)
- **本机(xuan-main**Node pm2 跑通,dev 环境 vite(5173) 代理正常
- **VPSxuan-vps / 101.34.227.188Debian 12**
- Node v22.23.1 + pm2 7.0.3(已装)
- 项目 git clone 在 `/opt/cc-square`gitee: xuan-java/cc-square
- Node 服务 pm2 运行,脚本 `/opt/cc-square/server/server.js`,端口 48080,内存 ~45MB
- `.env` + `config.js``/opt/cc-square/server/`config.js 需手动补,不入 git
- 旧目录 `/opt/cc-square-server` 已删/不用,统一 `/opt/cc-square`
- 前端 dist 已部署 `/usr/share/nginx/html`(保留 admin/ariang/tools 子目录)
- 备份:`/usr/share/nginx/html.bak.20260812``htmlbak-cc-20260812.tar.gz`
- Redis 已初始化(120 书签 / 3 引擎)
- **nginx**:主站 climbcube.conf `location /api { rewrite ^/api(.*)$ $1 break; proxy_pass http://localhost:48080; }`
- apiadmin→8080, yudaoapi→内网192.168.195.185:48080(旧配置保留)
### 验证结果(生产外网)
- `https://www.climbcube.cn/` → 200,前端正常
- `https://www.climbcube.cn/api/tab/{engine,bookmark,menu,quick}` → 全 200
- bookmark 返回 8 个真实分类(资源15/AI5/文档20/国家站点5/学习11/工具22/工作台25/办公15),无 nav-left
### git 工作流约定(避免再冲突)
- 统一走 git:本机 commit→push → VPS `git pull` → pm2 restart
- **禁止直接 scp 覆盖 VPS 生产文件**(会绕过 git 产生冲突)
- 本次冲突解决:git checkout -- server.js(内容与远端一致)+ pull fast-forward
### 更新生效规则
- 改 server.js/config.js → `pm2 restart cc-square`
- 改 package.json 依赖 → `npm install` + restart
- 改前端 src/* → `npm run build` + 部署 dist 到 nginx
- 改 .env → `set -a && source .env` + restart
### 遗留 / 待办
- [ ] 天气接口需高德 key(amapKey 占位,未启用)
- [ ] 安全建议:readonly host `%` 建议收窄(需用户确认后执行)
- [ ] 前端 dist 已部署,但 git 仓库 /usr/share/nginx/html 与 /opt/cc-square 前端源码的关系需注意(dist 不入 git?待确认)
### 环境备注
- 本机 shell 是 zsh(注意 pkill/zsh 通配符坑;ssh 到 VPS 时 pm2/curl 需绝对路径或 export PATH
- VPS 内存 3.7G,磁盘 69G/32G 已用
- VPS 多文件 debian 属主;Node 服务 root 运行(pm2