From a9ec1de1bff64f2b111f9e55b0c5c9a753f784a0 Mon Sep 17 00:00:00 2001 From: Peanut Date: Wed, 18 Mar 2026 20:26:28 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E5=88=9B=E5=BB=BA=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=9F=9F=E5=90=8D=E9=85=8D=E7=BD=AE=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-03-18-mini-program-domain-config.md | 225 ++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 docs/superpowers/plans/2026-03-18-mini-program-domain-config.md diff --git a/docs/superpowers/plans/2026-03-18-mini-program-domain-config.md b/docs/superpowers/plans/2026-03-18-mini-program-domain-config.md new file mode 100644 index 0000000..2b7121b --- /dev/null +++ b/docs/superpowers/plans/2026-03-18-mini-program-domain-config.md @@ -0,0 +1,225 @@ +# 小程序环境配置统一使用域名访问 Implementation Plan + +> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** 修改小程序所有环境配置文件,统一使用域名 `lifescript.happylifeos.com` 通过 HTTPS/WSS 协议访问服务器后端 API。 + +**Architecture:** 修改 `.env.development`、`.env.test`、`.env.production` 三个环境配置文件,将 API 和 WebSocket 地址从 localhost/IP 地址改为域名访问,使用 HTTPS 和 WSS 加密协议。 + +**Tech Stack:** UniApp, Vite, 环境变量配置 + +--- + +## Chunk 1: 环境配置文件修改 + +### Task 1: 修改开发环境配置 (.env.development) + +**Files:** +- Modify: `mini-program/.env.development` + +- [ ] **Step 1: 修改 .env.development 文件内容** + +将以下内容: +```bash +VITE_APP_ENV=dev +VITE_API_BASE_URL=http://localhost:19089/api +VITE_WS_URL=ws://localhost:19089 +VITE_DEBUG=true +``` + +修改为: +```bash +# 开发环境配置(本地开发调试) +VITE_APP_ENV=dev +VITE_API_BASE_URL=https://lifescript.happylifeos.com/api +VITE_WS_URL=wss://lifescript.happylifeos.com/ws +VITE_DEBUG=true +``` + +- [ ] **Step 2: 验证文件格式正确** + +确认文件内容没有多余的空格或格式问题 + +- [ ] **Step 3: 提交更改** + +```bash +git add mini-program/.env.development +git commit -m "fix: 开发环境配置改为域名访问 (HTTPS/WSS)" +``` + +--- + +### Task 2: 修改测试环境配置 (.env.test) + +**Files:** +- Modify: `mini-program/.env.test` + +- [ ] **Step 1: 修改 .env.test 文件内容** + +将以下内容: +```bash +# 体验环境配置(小程序体验版) +VITE_APP_ENV=test +VITE_API_BASE_URL=http://101.200.208.45:19089/api +VITE_WS_URL=ws://101.200.208.45:19089 +VITE_DEBUG=true +``` + +修改为: +```bash +# 测试环境配置(小程序体验版) +VITE_APP_ENV=test +VITE_API_BASE_URL=https://lifescript.happylifeos.com/api +VITE_WS_URL=wss://lifescript.happylifeos.com/ws +VITE_DEBUG=true +``` + +- [ ] **Step 2: 验证文件格式正确** + +确认文件内容没有多余的空格或格式问题 + +- [ ] **Step 3: 提交更改** + +```bash +git add mini-program/.env.test +git commit -m "fix: 测试环境配置改为域名访问 (HTTPS/WSS)" +``` + +--- + +### Task 3: 修改生产环境配置 (.env.production) + +**Files:** +- Modify: `mini-program/.env.production` + +- [ ] **Step 1: 修改 .env.production 文件内容** + +将以下内容(注意:当前文件第一行是 `VITE_APP_ENV=prod` 但文件名是 production,需确认内容): + +```bash +VITE_APP_ENV=prod +VITE_API_BASE_URL=http://101.200.208.45:19089/api +VITE_WS_URL=ws://101.200.208.45:19089 +VITE_DEBUG=false +``` + +修改为: +```bash +# 生产环境配置(小程序正式版) +VITE_APP_ENV=prod +VITE_API_BASE_URL=https://lifescript.happylifeos.com/api +VITE_WS_URL=wss://lifescript.happylifeos.com/ws +VITE_DEBUG=false +``` + +- [ ] **Step 2: 验证文件格式正确** + +确认文件内容没有多余的空格或格式问题 + +- [ ] **Step 3: 提交更改** + +```bash +git add mini-program/.env.production +git commit -m "fix: 生产环境配置改为域名访问 (HTTPS/WSS)" +``` + +--- + +## Chunk 2: 代码验证和文档更新 + +### Task 4: 验证环境配置代码兼容性 + +**Files:** +- Read: `mini-program/src/config/env.js` +- Read: `mini-program/src/utils/env.ts` + +- [ ] **Step 1: 检查 src/config/env.js 文件** + +确认文件中的配置逻辑能够正确处理 HTTPS 和 WSS 协议地址 + +预期:该文件只是读取环境变量,不需要修改 + +- [ ] **Step 2: 检查 src/utils/env.ts 文件** + +确认请求封装代码能够正确处理 HTTPS 和 WSS 协议地址 + +预期:该文件使用 API_BASE_URL 拼接请求地址,不需要修改 + +- [ ] **Step 3: 提交验证结果** + +如果代码不需要修改,跳过提交 + +--- + +### Task 5: 更新 README.md 文档 + +**Files:** +- Modify: `mini-program/README.md` + +- [ ] **Step 1: 更新环境配置说明** + +将环境配置表格更新为: + +```markdown +| 文件 | 说明 | API 地址 | WebSocket 地址 | +|------|------|----------|----------------| +| `.env.development` | 开发环境配置 | https://lifescript.happylifeos.com/api | wss://lifescript.happylifeos.com/ws | +| `.env.test` | 测试环境配置 | https://lifescript.happylifeos.com/api | wss://lifescript.happylifeos.com/ws | +| `.env.production` | 生产环境配置 | https://lifescript.happylifeos.com/api | wss://lifescript.happylifeos.com/ws | +``` + +- [ ] **Step 2: 更新各环境配置示例** + +将三个环境的配置示例都更新为使用域名的格式 + +- [ ] **Step 3: 提交更改** + +```bash +git add mini-program/README.md +git commit -m "docs: 更新环境配置文档说明" +``` + +--- + +### Task 6: 验证小程序编译 + +**Files:** +- Build Output: `mini-program/unpackage/dist/test/mp-weixin` + +- [ ] **Step 1: 执行测试环境编译** + +```bash +cd mini-program +npm run build:mp-weixin:test +``` + +预期:编译成功,无错误 + +- [ ] **Step 2: 验证编译产物中的环境变量** + +检查编译后的文件中环境变量是否正确注入 + +预期:API_BASE_URL 和 WS_URL 应为域名地址 + +- [ ] **Step 3: 提交验证** + +如果编译成功,记录验证结果 + +--- + +## 验证步骤 + +完成所有任务后,执行以下验证: + +1. **配置验证**: 确认三个环境配置文件都已更新为域名访问 +2. **编译验证**: 确认小程序可以正常编译 +3. **代码验证**: 确认现有代码能够正确处理 HTTPS/WSS 地址 + +--- + +## 注意事项 + +1. 所有环境都使用 HTTPS/WSS 协议,微信小程序要求加密连接 +2. 开发环境也使用服务器 API,本地无需启动后端服务 +3. 确保服务器 CORS 配置允许小程序域名访问 +4. 确保服务器 Nginx 配置了正确的 SSL 证书