Files
pangolin/dev/run-local.md
T
wangjia 6979411c1d feat: 档2 接真后端 — mac app 真注册/登录/拉节点
dev 本机置备(新增 dev/):
- docker-compose.yml: MySQL :13306 + Redis :16379(避让本机已占的 3306/6379)
- run-local.sh 一键: 起容器→openssl 生成密钥(dev/.local gitignore)→migrate→
  seed→启动 server :18080(避让 8080);LogMailer 把验证码打日志
- seed.sql(1 provider + 1 HK 节点)、run-local.md 手册、.gitignore

后端两处修复(本地无 gRPC 场景,注释意图与代码不符的 bug):
- main.go: 无 gRPC 时真正构造 Hub-only nodeSvc(原只建 hub 没赋值),/v1/nodes 才能挂
- main.go: /me 改 Route 子路由根 Get,修 Get("/me")+Route("/me") 冲突致 404

客户端接真后端:
- token_store: MacOsOptions(useDataProtectionKeyChain:false) 修 keychain -34018
- auth_screen: 删 dev 旁路(test 账户内存登录),所有登录走真 API

验收: 后端 curl 端到端全通(验证码→注册→登录→/nodes→/me);
server go build/vet/test 通过, client analyze 0 + test 84

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 13:27:58 +08:00

62 lines
2.4 KiB
Markdown
Raw 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.
# 本地开发:一键起后端
让后端在本机真跑起来(auth 注册/登录 + 节点列表),供 mac app 接真后端调试。
## 前置
- Docker(起 MySQL + Redis
- Go`/opt/homebrew/bin` 在 PATH,脚本已内置)
- openssl(生成 JWT 密钥)
## 一键启动
```bash
cd <项目根> # pangolin/
bash dev/run-local.sh
```
脚本做的事:
1. `docker compose``pangolin-dev-mysql`:13306+ `pangolin-dev-redis`(:16379,避让本机已占用的 3306/6379),等 MySQL 就绪
2. 首次生成密钥到 `dev/.local/`gitignore):RS256 JWT 私钥/公钥、`webhook_secret``derive_key`
3. 组装 env`DB_DSN`/`WEBHOOK_SECRET`/`NODE_DERIVE_KEY`/`JWT_*`),不配 SMTP → 验证码打日志
4. `go run ./cmd/migrate up`(建表 + plans seed),`dev/seed.sql` 插一个 HK 测试节点
5. 前台启动 `go run ./cmd/server`:18080)—— **注册验证码会打印在终端日志**
停止:`Ctrl+C`(停 server);`docker compose -f dev/docker-compose.yml down` 停容器(加 `-v` 清库)。
## 端到端验证(curl
```bash
# 1) 发验证码(看 server 终端日志读 6 位码)
curl -XPOST localhost:18080/v1/auth/code -H 'Content-Type: application/json' \
-d '{"email":"me@x.com"}'
# 2) 注册(填上一步日志里的码)
curl -XPOST localhost:18080/v1/auth/register -H 'Content-Type: application/json' \
-d '{"email":"me@x.com","code":"<码>","password":"pass1234"}'
# → {"access_token":"...","refresh_token":"..."}
# 3) 拉节点列表(带 access token
curl localhost:18080/v1/nodes -H 'Authorization: Bearer <access>'
# → 含 HK 测试节点
# 4) 当前用户
curl localhost:18080/v1/me -H 'Authorization: Bearer <access>'
```
## mac app 接它
```bash
cd client
# 客户端默认连 :8080;本机 8080 被占用,dev 后端在 18080,故显式指定:
flutter run -d macos --dart-define=PANGOLIN_API_URL=http://localhost:18080
```
注册页输真邮箱 → 发验证码(后端日志读码)→ 填码+密码 → 进主界面 → 节点页显示真节点(HK·测试)。
## 说明
- **密钥纯本地玩具**`dev/.local/` 不进 git;换机重跑脚本会重新生成。
- **节点 endpoint 占位**`127.0.0.1:11443`):档 2 只验证列表 + connect 配置渲染,**不真连**。真连接出网见档 3。
- 不连 EC2 生产 MySQL(本地隔离,避免污染线上)。