fix: 修复 PostHog 生产环境配置问题

## 问题描述
生产环境部署后,PostHog 只收到 localhost:3000 的错误报告,而不是生产环境的真实 URL。

## 根本原因
构建脚本未显式加载生产环境配置文件,导致 PostHog API Key 和 Host 配置未正确嵌入到打包文件中。

## 解决方案
1. 新增 `.env.production` 生产环境专用配置文件
   - 包含正确的 PostHog API Key 和 Host
   - 设置 REACT_APP_ENV=production
   - 禁用 Mock 数据 (REACT_APP_ENABLE_MOCK=false)
   - 配置生产 API 地址

2. 修改 package.json 构建脚本
   - 使用 env-cmd 显式加载 .env.production
   - 确保构建时环境变量正确嵌入

## 影响范围
-  生产环境构建: 现在会正确加载配置
-  PostHog 功能: 将使用正确的配置初始化
-  开发环境: 无影响,仍使用各自的环境文件
-  部署流程: 服务器构建时自动使用新配置

## 测试计划
1. 本地执行 npm run build 验证构建成功
2. 部署到生产环境
3. 验证 PostHog 后台收到正确的生产 URL

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zdl
2025-11-03 18:42:58 +08:00
parent 82cb0b4034
commit 0e66bb471f
2 changed files with 43 additions and 1 deletions

View File

@@ -101,7 +101,7 @@
"frontend:test": "NODE_OPTIONS='--openssl-legacy-provider --max_old_space_size=4096' env-cmd -f .env.test craco start",
"dev": "npm start",
"backend": "python app_2.py",
"build": "NODE_OPTIONS='--openssl-legacy-provider --max_old_space_size=4096' craco build && gulp licenses",
"build": "NODE_OPTIONS='--openssl-legacy-provider --max_old_space_size=4096' env-cmd -f .env.production craco build && gulp licenses",
"build:analyze": "NODE_OPTIONS='--openssl-legacy-provider --max_old_space_size=4096' ANALYZE=true craco build",
"test": "craco test --env=jsdom",
"eject": "react-scripts eject",