befly-tpl 3.4.16 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.development CHANGED
@@ -2,7 +2,7 @@ NODE_ENV="development"
2
2
  # 调试模式 (1=开启, 0=关闭, development模式下默认开启)
3
3
  DEBUG=1
4
4
  # 项目名称
5
- APP_NAME="易接口"
5
+ APP_NAME="易接口1"
6
6
  APP_PORT=3000
7
7
  # 监听端口
8
8
  APP_HOST="127.0.0.1"
@@ -28,12 +28,12 @@ LOG_MAX_SIZE=52428800 # 50MB
28
28
  # 时区
29
29
  TZ="Asia/Shanghai"
30
30
  # 跨域配置
31
- ALLOWED_ORIGIN=""
32
- ALLOWED_METHODS="GET, POST, PUT, DELETE, OPTIONS"
33
- ALLOWED_HEADERS="Content-Type, Authorization, authorization, token"
34
- EXPOSE_HEADERS="Content-Range, X-Content-Range, Authorization, authorization, token"
35
- MAX_AGE=86400 # 1天
36
- ALLOW_CREDENTIALS="true"
31
+ CORS_ALLOWED_ORIGIN=""
32
+ CORS_ALLOWED_METHODS="GET, POST, PUT, DELETE, OPTIONS"
33
+ CORS_ALLOWED_HEADERS="Content-Type, Authorization, authorization, token"
34
+ CORS_EXPOSE_HEADERS="Content-Range, X-Content-Range, Authorization, authorization, token"
35
+ CORS_MAX_AGE=86400 # 1天
36
+ CORS_ALLOW_CREDENTIALS="true"
37
37
  # 数据库配置(DB_* 通用参数)
38
38
  DB_ENABLE=1
39
39
  DB_TYPE="mysql" # 支持 sqlite | mysql | postgresql
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly-tpl",
3
- "version": "3.4.16",
3
+ "version": "3.5.0",
4
4
  "description": "Befly 3.0 TypeScript Template",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -31,10 +31,13 @@
31
31
  ],
32
32
  "type": "module",
33
33
  "dependencies": {
34
- "befly": "^3.4.15"
34
+ "befly": "3.5.0"
35
35
  },
36
36
  "engines": {
37
37
  "bun": ">=1.3.0"
38
38
  },
39
- "gitHead": "f7fad19e6c07b776a4a3c1aa83d09497ababb719"
39
+ "gitHead": "6d065b50bd57e1330a81d5a62423b204a2a49205",
40
+ "devDependencies": {
41
+ "dotenv": "^17.2.3"
42
+ }
40
43
  }
package/pm2.config.cjs CHANGED
@@ -12,33 +12,51 @@
12
12
  * 7. 保存配置:pm2 save
13
13
  * 8. 开机自启:pm2 startup
14
14
  *
15
- * 环境变量加载:
16
- * - 默认使用生产环境:--env-file=.env.production
15
+ * 环境变量说明:
16
+ * - 使用 dotenv 模块读取 .env.production 文件
17
+ * - PM2 会在进程启动时直接注入这些环境变量
17
18
  *
18
19
  * 注意:PM2 配置文件必须使用 CommonJS 格式(.cjs),不支持 ESM
19
20
  */
20
21
 
22
+ const dotenv = require('dotenv');
23
+ const path = require('path');
24
+
25
+ // 使用 dotenv 读取 .env.production 文件
26
+ const result = dotenv.config({
27
+ path: path.join(__dirname, '.env.production'),
28
+ override: true
29
+ });
30
+
31
+ if (result.error) {
32
+ console.error('读取 .env.production 失败:', result.error.message);
33
+ }
34
+
35
+ // 获取解析后的环境变量
36
+ const productionEnv = result.parsed || {};
37
+
21
38
  module.exports = {
22
39
  apps: [
23
40
  {
24
41
  name: 'befly',
25
- script: 'bun',
26
- args: 'run --env-file=.env.production main.ts',
42
+ script: 'main.ts',
43
+ interpreter: 'bun',
27
44
 
28
45
  // 集群模式配置
29
- instances: 4, // 实例数量,可设置为 'max' 使用所有 CPU
46
+ instances: 2, // 实例数量,可设置为 'max' 使用所有 CPU
30
47
  exec_mode: 'cluster', // 集群模式
31
48
 
32
49
  // 自动重启配置
33
50
  autorestart: true,
34
51
  watch: false,
35
- max_memory_restart: '1G', // 内存超过 1G 自动重启
52
+ max_memory_restart: '500M', // 内存超过 500M 自动重启
36
53
 
37
54
  // 日志配置
38
- error_file: './logs/pm2-error.log',
39
- out_file: './logs/pm2-out.log',
40
55
  log_date_format: 'YYYY-MM-DD HH:mm:ss',
41
- merge_logs: true
56
+ merge_logs: true,
57
+
58
+ // 从 .env.production 动态加载的环境变量(使用 Bun API)
59
+ env: productionEnv
42
60
  }
43
61
  ]
44
62
  };