119 lines
3.1 KiB
Markdown
119 lines
3.1 KiB
Markdown
# 部署配置说明
|
|
|
|
## API 地址配置
|
|
|
|
本项目已将所有 API 地址统一配置在 `app/config/api-config.ts` 文件中,支持多种配置方式:
|
|
|
|
### 1. 默认配置
|
|
|
|
在 `api-config.ts` 中定义了不同环境的默认配置:
|
|
|
|
- **development** (开发环境)
|
|
- **testing** (测试环境)
|
|
- **production** (生产环境)
|
|
- **staging** (预发布环境)
|
|
|
|
### 2. 环境变量配置 (推荐)
|
|
|
|
可以通过环境变量覆盖默认配置,支持以下环境变量:
|
|
|
|
```bash
|
|
# 指定环境类型
|
|
NEXT_PUBLIC_API_ENV=production
|
|
|
|
# API基础URL
|
|
NEXT_PUBLIC_API_BASE_URL=http://your-api-server.com:3000
|
|
|
|
# 文档服务URL
|
|
NEXT_PUBLIC_DOCUMENT_URL=http://your-document-server.com:9000/docauditai/
|
|
|
|
# 文档上传API URL
|
|
NEXT_PUBLIC_UPLOAD_URL=http://your-upload-server.com:8008/admin/documents/upload
|
|
|
|
# PostgREST URL (可选)
|
|
NEXT_PUBLIC_POSTGREST_URL=http://your-postgrest-server.com:3000
|
|
```
|
|
|
|
### 3. 部署方式
|
|
|
|
#### 方式一:环境变量文件 (推荐)
|
|
|
|
1. 在项目根目录创建 `.env.local` 文件:
|
|
|
|
```bash
|
|
# .env.local
|
|
NODE_ENV=production
|
|
NEXT_PUBLIC_API_BASE_URL=http://production-api.company.com:3000
|
|
NEXT_PUBLIC_DOCUMENT_URL=http://production-docs.company.com:9000/docauditai/
|
|
NEXT_PUBLIC_UPLOAD_URL=http://production-upload.company.com:8008/admin/documents/upload
|
|
```
|
|
|
|
2. 构建和启动应用:
|
|
|
|
```bash
|
|
npm run build
|
|
npm start
|
|
```
|
|
|
|
#### 方式二:直接修改配置文件
|
|
|
|
直接编辑 `app/config/api-config.ts` 中对应环境的配置:
|
|
|
|
```typescript
|
|
// 修改生产环境配置
|
|
production: {
|
|
baseUrl: 'http://your-production-api.com:3000',
|
|
documentUrl: 'http://your-production-docs.com:9000/docauditai/',
|
|
uploadUrl: 'http://your-production-upload.com:8008/admin/documents/upload',
|
|
}
|
|
```
|
|
|
|
#### 方式三:Docker 环境变量
|
|
|
|
在 Docker 部署时传入环境变量:
|
|
|
|
```bash
|
|
docker run -d \
|
|
-e NODE_ENV=production \
|
|
-e NEXT_PUBLIC_API_BASE_URL=http://api.company.com:3000 \
|
|
-e NEXT_PUBLIC_DOCUMENT_URL=http://docs.company.com:9000/docauditai/ \
|
|
-e NEXT_PUBLIC_UPLOAD_URL=http://upload.company.com:8008/admin/documents/upload \
|
|
your-app-image
|
|
```
|
|
|
|
### 4. 配置项说明
|
|
|
|
| 配置项 | 用途 | 示例 |
|
|
|--------|------|------|
|
|
| `API_BASE_URL` | 主要API服务地址 | `http://nas.7bm.co:3000` |
|
|
| `DOCUMENT_URL` | 文档下载服务地址 | `http://nas.7bm.co:9000/docauditai/` |
|
|
| `UPLOAD_URL` | 文档上传API地址 | `http://172.16.0.58:8008/admin/documents/upload` |
|
|
|
|
### 5. 文件影响范围
|
|
|
|
以下文件已更新使用统一配置:
|
|
|
|
- `app/api/axios-client.ts` - 使用 `API_BASE_URL` 和 `DOCUMENT_URL`
|
|
- `app/api/files/files-upload.ts` - 使用 `UPLOAD_URL`
|
|
|
|
### 6. 验证配置
|
|
|
|
在开发环境下,控制台会输出当前使用的配置信息,便于调试:
|
|
|
|
```
|
|
📦 API配置信息: {
|
|
environment: "development",
|
|
config: {
|
|
baseUrl: "http://nas.7bm.co:3000",
|
|
documentUrl: "http://nas.7bm.co:9000/docauditai/",
|
|
uploadUrl: "http://172.16.0.58:8008/admin/documents/upload"
|
|
}
|
|
}
|
|
```
|
|
|
|
### 7. 注意事项
|
|
|
|
1. 环境变量必须以 `NEXT_PUBLIC_` 开头才能在客户端使用
|
|
2. 修改环境变量后需要重新构建应用
|
|
3. URL 地址末尾的斜杠要保持一致
|
|
4. 确保所有服务地址在目标环境中可访问 |