feat: 环境配置纳入版本管理并更新文档
- 将 .env 和 .env.local 纳入版本管理 - 更新 .gitignore,移除对环境文件的忽略 - 在 README.md 中添加详细的数据库配置和启动说明 - 同步 server/.env 与项目根目录配置 - 修复后端数据库连接问题
This commit is contained in:
@@ -48,27 +48,65 @@ GovAI/
|
||||
- PostgreSQL 15+
|
||||
- Redis 7+
|
||||
|
||||
### 2. 后端启动
|
||||
### 2. 数据库配置
|
||||
|
||||
**PostgreSQL 配置**
|
||||
```bash
|
||||
cd server
|
||||
cp .env.example .env # 编辑配置
|
||||
go run cmd/server/main.go
|
||||
```
|
||||
# 数据库: govai_portal
|
||||
# 用户: freedak (无密码)
|
||||
# 端口: 5432
|
||||
|
||||
### 3. 数据库初始化
|
||||
# 确保 PostgreSQL 正在运行
|
||||
lsof -nP -iTCP:5432 -sTCP:LISTEN
|
||||
|
||||
```bash
|
||||
# 创建数据库
|
||||
createdb govai
|
||||
# 创建数据库(如果不存在)
|
||||
createdb govai_portal
|
||||
|
||||
# 运行迁移
|
||||
psql -d govai -f server/migrations/000001_init.up.sql
|
||||
psql -d govai -f server/migrations/000002_categories_and_applications.up.sql
|
||||
psql -d govai_portal -f server/migrations/000001_init.up.sql
|
||||
psql -d govai_portal -f server/migrations/000002_categories_and_applications.up.sql
|
||||
# ... 运行所有迁移文件
|
||||
|
||||
# 导入种子数据
|
||||
psql -d govai -f server/migrations/seed.sql
|
||||
psql -d govai_portal -f server/migrations/seed.sql
|
||||
```
|
||||
|
||||
**Redis 配置**
|
||||
```bash
|
||||
# 端口: 6379
|
||||
# 确保 Redis 正在运行
|
||||
redis-cli ping
|
||||
```
|
||||
|
||||
**环境变量配置**
|
||||
|
||||
项目已包含配置文件 `.env` 和 `server/.env`(已纳入版本管理),主要配置:
|
||||
|
||||
```bash
|
||||
# 数据库连接
|
||||
DATABASE_URL=postgres://freedak:@localhost:5432/govai_portal?sslmode=disable
|
||||
|
||||
# Redis 连接
|
||||
REDIS_URL=redis://localhost:6379
|
||||
|
||||
# 后端服务
|
||||
SERVER_HOST=0.0.0.0
|
||||
SERVER_PORT=8080
|
||||
```
|
||||
|
||||
⚠️ **重要提示**:
|
||||
- 后端启动时会从工作目录读取 `.env` 文件
|
||||
- 确保 `server/.env` 与项目根目录 `.env` 内容同步
|
||||
- 数据库连接失败会导致 API 返回 500 错误
|
||||
|
||||
### 3. 后端启动
|
||||
|
||||
```bash
|
||||
cd server
|
||||
go run ./cmd/server
|
||||
|
||||
# 验证启动
|
||||
curl http://localhost:8080/api/v1/organizations
|
||||
```
|
||||
|
||||
### 4. 前端启动
|
||||
|
||||
Reference in New Issue
Block a user