CLI:本地开发环境
本章说明如何仅用命令行搭建本地开发环境。
1. 安装依赖
Section titled “1. 安装依赖”在仓库根目录执行:
pnpm install2. 执行本地 D1 迁移
Section titled “2. 执行本地 D1 迁移”每个使用 D1 的后端服务都需要本地数据库 schema。逐个执行迁移:
cd backend/node1-auth-service && npx wrangler d1 migrations apply zship-auth --local && cd ../..cd backend/node2-support-service && npx wrangler d1 migrations apply zship-support --local && cd ../..cd backend/node3-pay-service && npx wrangler d1 migrations apply zship-pay --local && cd ../..cd backend/node4-notify-service && npx wrangler d1 migrations apply zship-notify --local && cd ../..cd backend/node5-blog-service && npx wrangler d1 migrations apply zship-blog --local && cd ../..cd backend/node7-site-service && npx wrangler d1 migrations apply zship-site --local && cd ../..cd backend/node8-prompt-service && npx wrangler d1 migrations apply zship-prompt --local && cd ../..cd backend/node9-checkin-service && npx wrangler d1 migrations apply zship-checkin --local && cd ../..cd backend/node10-ai-service && npx wrangler d1 migrations apply zship-ai --local && cd ../..如有 per-service 脚本也可使用:
pnpm db:migrate:localpnpm db:migrate:support:local# ... 其他服务3. 启动后端 Worker
Section titled “3. 启动后端 Worker”开多个终端,或使用进程管理工具。在仓库根目录:
# 终端 1 - Auth(端口 8787)cd backend/node1-auth-service && npx wrangler dev
# 终端 2 - Support(端口 8788)cd backend/node2-support-service && npx wrangler dev --port 8788
# 终端 3 - Paycd backend/node3-pay-service && npx wrangler dev --port 8789
# ... node4 到 node10 同理或使用根目录脚本:
pnpm dev:auth # node1-authpnpm dev:support # node2-support# 等等4. 启动前端应用
Section titled “4. 启动前端应用”在另外的终端:
# Web(端口 4321)pnpm dev:web
# Admin(端口 4322)pnpm dev:adminapps/web 本地环境变量:在 apps/web 下新建或维护 .env,变量名与线上一致,例如 AUTH_SERVICE_URL、APP_KEY、BLOG_API_URL(常用列表见 05. 绑定域名和环境变量)。构建与 SSR 通过 import.meta.env 读取;site.ts 里是类型化默认与展示配置,需要被 env 覆盖的键仍以环境变量为准(与代码里 import.meta.env.XXX || 默认值 的写法一致)。
- Web: http://localhost:4321
- Admin: http://localhost:4322
- Auth: http://localhost:8787
6. 检查清单
Section titled “6. 检查清单”- 依赖已安装
- 所有 D1 本地迁移已执行
- 后端 Worker 已启动
- 前端应用已启动
- 能在浏览器访问 web 和 admin