88 lines
2.9 KiB
Markdown
88 lines
2.9 KiB
Markdown
当前数据库是本机Homebrew PostgreSQL 15,数据库名为 bill_query,端口5432,仅监听 localhost;当前用户 freedak 是超级用户,本机认证方式为 trust。这适合本机开发,但不适合直接照搬到服务器生产环境。前端浏览器也不应直接连接PostgreSQL,必须通过后端API访问。
|
||
|
||
## 登录账号
|
||
|
||
| 用户名 | 密码 | 角色 |
|
||
|--------|------|------|
|
||
| 总部管理员 | 123 | hq |
|
||
| 区域经理 | 123 | regional |
|
||
| 潘家园店长 | 123 | store |
|
||
| 商品部 | 123 | dept |
|
||
|
||
## 本地开发启动
|
||
|
||
后端服务和 frp 隧道已配置为 macOS launchd 系统级服务,开机自动启动,崩溃自动重启,与 IDE 无关。
|
||
|
||
### 系统级服务(launchd)
|
||
|
||
已创建两个 LaunchAgent:
|
||
|
||
| 服务 | plist | 日志 |
|
||
|------|-------|------|
|
||
| 后端 (localhost:3333) | `~/Library/LaunchAgents/com.sbrain.backend.plist` | `~/Library/Logs/sbrain-backend.log` |
|
||
| frp 隧道 (13333→3333) | `~/Library/LaunchAgents/com.frp.client.plist` | `~/Library/Logs/frpc.log` |
|
||
|
||
两个服务均配置了 `KeepAlive: true`,崩溃后自动重启。开机/登录后自动启动,关闭 IDE 和终端不影响运行。
|
||
|
||
#### 管理命令
|
||
|
||
```bash
|
||
# 停止服务
|
||
launchctl unload ~/Library/LaunchAgents/com.sbrain.backend.plist
|
||
launchctl unload ~/Library/LaunchAgents/com.frp.client.plist
|
||
|
||
# 启动服务
|
||
launchctl load ~/Library/LaunchAgents/com.sbrain.backend.plist
|
||
launchctl load ~/Library/LaunchAgents/com.frp.client.plist
|
||
|
||
# 查看日志
|
||
tail -f ~/Library/Logs/sbrain-backend.log
|
||
tail -f ~/Library/Logs/frpc.log
|
||
|
||
# 检查状态
|
||
curl -s http://localhost:3333/api/health
|
||
pgrep -l frpc
|
||
```
|
||
|
||
### 手动启动(备用,launchd 未运行时)
|
||
|
||
#### 1. 启动后端服务
|
||
|
||
```bash
|
||
cd server && npm run dev
|
||
```
|
||
|
||
后端运行在 `http://localhost:3333`,连接本地 PostgreSQL(`localhost:5432`,数据库 `bill_query`)。
|
||
|
||
#### 2. 启动 frp 隧道
|
||
|
||
线上 Nginx 将 `/api/` 代理到远程 `127.0.0.1:13333`,通过 frp tcp 代理转发到本地后端 3333 端口:
|
||
|
||
frpc 配置(`/Users/freedak/frp/frpc.toml`)中已包含 dm-api 代理:
|
||
|
||
```toml
|
||
[[proxies]]
|
||
name = "dm-api"
|
||
type = "tcp"
|
||
localIP = "127.0.0.1"
|
||
localPort = 3333
|
||
remotePort = 13333
|
||
```
|
||
|
||
重启 frpc:
|
||
|
||
```bash
|
||
kill -9 $(pgrep frpc); cd /Users/freedak/frp && ./frpc -c frpc.toml &
|
||
```
|
||
|
||
### 访问
|
||
|
||
- **线上前端**:`https://dm.all8ai.top`(API请求通过 frp 隧道转发到本地后端)
|
||
- **本地前端开发**:`cd client && npm run dev`,访问 `http://localhost:5173`(Vite proxy 自动转发 `/api` 到 `localhost:3333`)
|
||
|
||
### 注意事项
|
||
|
||
- 本地 PostgreSQL 端口 5432 被 Homebrew PostgreSQL 占用,数据库 `bill_query` 在本地
|
||
- frp 隧道将远程 13333 映射到本地 3333,服务器 Nginx 配置 `/api/` → `127.0.0.1:13333`
|
||
- launchd 服务开机自启,关闭 IDE/终端不影响;仅注销/关机时停止,下次登录/开机自动恢复
|
||
- `server/.env` 中 `DB_PORT=5432` 连接本地数据库,不要改为 5433 |