diff --git a/.env b/.env new file mode 100644 index 0000000..4009615 --- /dev/null +++ b/.env @@ -0,0 +1,21 @@ +# 数据库配置 +DB_HOST=localhost +DB_PORT=33306 +DB_USER=root +DB_PASSWORD=123456 +DB_NAME=employee_performance + +# JWT 配置 +JWT_SECRET=dev_jwt_secret_please_change_in_production + +# FastGPT API 配置 +FASTGPT_API_KEY=fastgpt-oEipxYa5BfVaeGDj74iAXi8YSkWyye07lTNYuj7yydsEKAc4Hp2Z2RDbxsxc4TuZ +FASTGPT_API_URL=https://cloud.fastgpt.cn/api/v1/chat/completions +FASTGPT_MODEL=gpt-4 + +# 代理配置(Node.js 不自动读取系统代理,需手动配置) +HTTPS_PROXY=http://127.0.0.1:7890 + +# 服务器配置 +PORT=3001 +NODE_ENV=development diff --git a/backend/.env.production.example b/backend/.env.production.example new file mode 100644 index 0000000..cd3873e --- /dev/null +++ b/backend/.env.production.example @@ -0,0 +1,27 @@ +# 生产环境配置示例 +# 根据您的部署方式调整以下配置 + +# 数据库配置 +# Docker Compose 部署:DB_HOST=db, DB_PORT=3306 (容器内部) +# 传统部署(数据库在本地):DB_HOST=localhost, DB_PORT=3306 +# 传统部署(数据库在远程服务器):DB_HOST=数据库服务器IP, DB_PORT=3306 +DB_HOST=localhost +DB_PORT=3306 +DB_USER=root +DB_PASSWORD=your_secure_password_here +DB_NAME=employee_performance + +# JWT 配置(生产环境必须使用强密钥) +JWT_SECRET=generate_a_strong_random_string_at_least_32_chars_long + +# FastGPT API 配置 +FASTGPT_API_KEY=your_fastgpt_api_key_here +FASTGPT_API_URL=https://api.fastgpt.in/api/v1/chat/completions +FASTGPT_MODEL=gpt-4 + +# 代理配置(如果需要通过代理访问 FastGPT) +# HTTPS_PROXY=http://127.0.0.1:7890 + +# 服务器配置 +PORT=3001 +NODE_ENV=production \ No newline at end of file diff --git a/backend/check-api-response.ts b/backend/check-api-response.ts index d63a24d..4dbd32d 100644 --- a/backend/check-api-response.ts +++ b/backend/check-api-response.ts @@ -26,7 +26,7 @@ async function run() { { expiresIn: '1h' } ); - const { data } = await axios.get('http://localhost:3001/api/performance/employee/get', { + const { data } = await axios.get('http://47.238.126.111:33001/api/performance/employee/get', { params: { perfId: rec.perf_id }, headers: { Authorization: `Bearer ${token}` }, }); diff --git a/docker-compose.yml b/docker-compose.yml index e7d2ff8..5767479 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: MYSQL_USER: app_user MYSQL_PASSWORD: app_password ports: - - "3306:3306" + - "33306:3306" volumes: - mysql_data:/var/lib/mysql - ./backend/src/db/init.sql:/docker-entrypoint-initdb.d/init.sql @@ -52,7 +52,7 @@ services: PORT: 3001 NODE_ENV: development ports: - - "3001:3001" + - "33001:3001" volumes: - ./backend:/app - /app/node_modules @@ -75,9 +75,10 @@ services: depends_on: - backend environment: + VITE_API_BASE_URL: http://47.238.126.111:33001 VITE_API_URL: http://backend:3001 ports: - - "3000:3000" + - "2000:3000" volumes: - ./frontend:/app - /app/node_modules diff --git a/frontend/.env.production.example b/frontend/.env.production.example new file mode 100644 index 0000000..6c86ce7 --- /dev/null +++ b/frontend/.env.production.example @@ -0,0 +1,11 @@ +# 前端生产环境配置 +# 构建时使用的环境变量 + +# API 基础 URL +# Docker Compose 部署(前端独立构建,后端在 47.238.126.111:33001): +VITE_API_BASE_URL=http://47.238.126.111:33001 + +# 传统部署(Nginx 反向代理): +# VITE_API_BASE_URL=/api # 如果使用 Nginx 反向代理到后端,可以设置为相对路径 /api + +# 其他环境变量可根据需要添加 \ No newline at end of file diff --git a/frontend/src/api/http.ts b/frontend/src/api/http.ts index bf842dd..fac5a41 100644 --- a/frontend/src/api/http.ts +++ b/frontend/src/api/http.ts @@ -3,7 +3,7 @@ import axios from 'axios'; const TOKEN_KEY = 'auth_token'; const http = axios.create({ - baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:3001', + baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:33001', timeout: 15000, }); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index f2cfc95..225aede 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ port: 3000, proxy: { '/api': { - target: process.env.VITE_API_URL || 'http://localhost:3001', + target: process.env.VITE_API_URL || 'http://localhost:33001', changeOrigin: true, }, }, diff --git a/tmpclaude-490d-cwd b/tmpclaude-490d-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-490d-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-8604-cwd b/tmpclaude-8604-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-8604-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-b5ce-cwd b/tmpclaude-b5ce-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-b5ce-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-e9ac-cwd b/tmpclaude-e9ac-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-e9ac-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/tmpclaude-eb3d-cwd b/tmpclaude-eb3d-cwd new file mode 100644 index 0000000..0a8904c --- /dev/null +++ b/tmpclaude-eb3d-cwd @@ -0,0 +1 @@ +/c/Users/99095/Desktop/优一科技/performance-evaluation-system diff --git a/部署文档.md b/部署文档.md index 99a7793..ce8f705 100644 --- a/部署文档.md +++ b/部署文档.md @@ -81,7 +81,7 @@ cp .env.example .env ```env # 数据库配置 DB_HOST=localhost -DB_PORT=3306 +DB_PORT=33306 # Docker Compose 部署时使用 33306,传统部署请根据实际情况调整 DB_USER=perf_user DB_PASSWORD=你的数据库密码 DB_NAME=employee_performance @@ -158,7 +158,7 @@ npm install ```typescript const http = axios.create({ - baseURL: 'http://你的后端服务器IP:3001', + baseURL: 'http://47.238.126.111:33001', # Docker Compose 部署时使用 33001,传统部署使用 3001 timeout: 15000, }); ``` @@ -166,7 +166,7 @@ const http = axios.create({ 或者通过环境变量配置,在 `frontend/` 目录创建 `.env.production`: ```env -VITE_API_BASE_URL=http://你的后端服务器IP:3001 +VITE_API_BASE_URL=http://47.238.126.111:33001 # Docker Compose 部署时使用 33001,传统部署使用 3001 ``` ### 5.3 构建静态文件 @@ -184,7 +184,7 @@ npm run build ```nginx server { listen 80; - server_name 你的域名或IP; + server_name 47.238.126.111; # 前端静态文件 root /var/www/perf-system/dist; @@ -197,7 +197,7 @@ server { # 反向代理后端 API location /api/ { - proxy_pass http://127.0.0.1:3001; + proxy_pass http://127.0.0.1:33001; # Docker Compose 部署时使用 33001,传统部署使用 3001 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;