fix security and import validation

This commit is contained in:
lizhilun
2026-07-01 16:13:47 +08:00
parent 6467048f38
commit e69930799c
14 changed files with 498 additions and 163 deletions
+22 -2
View File
@@ -1,15 +1,31 @@
/**
* 应用配置
*/
const isProduction = process.env.NODE_ENV === 'production';
const jwtSecret = process.env.JWT_SECRET || '';
if (isProduction && !jwtSecret) {
throw new Error('JWT_SECRET must be set in production');
}
module.exports = {
// 服务器配置
port: process.env.PORT || 3000,
host: process.env.HOST || '0.0.0.0',
// JWT 配置
jwtSecret: process.env.JWT_SECRET || 'gamer-order-secret-2024',
jwtSecret: jwtSecret || 'dev-only-gamer-order-secret',
jwtExpiresIn: '7d',
// 注册默认关闭,生产环境可通过 ENABLE_REGISTRATION=true 显式开启
enableRegistration: process.env.ENABLE_REGISTRATION === 'true',
// CORS 配置:默认同源;如需跨域,用逗号分隔配置 CORS_ORIGINS
corsOrigins: (process.env.CORS_ORIGINS || '')
.split(',')
.map(s => s.trim())
.filter(Boolean),
// 缓存配置
cache: {
ttl: 2 * 60 * 1000, // 缓存有效期 2 分钟
@@ -22,6 +38,10 @@ module.exports = {
maxLimit: 100 // 最大每页条数
},
import: {
maxRecords: 5000
},
// 日志配置
log: {
level: process.env.LOG_LEVEL || 'info', // debug, info, warn, error
@@ -36,4 +56,4 @@ module.exports = {
// 允许的联系人字段
contactFields: ['boss', 'partner', 'source', 'destination']
};
};