diff --git a/src/modules/secret/secret.service.ts b/src/modules/secret/secret.service.ts index d36ff2f..939c66e 100644 --- a/src/modules/secret/secret.service.ts +++ b/src/modules/secret/secret.service.ts @@ -8,13 +8,12 @@ const FALLBACK_KEY = 'zhixi-secret-master-key-2026-32b!!'; function getMasterKey(): Buffer { const envKey = process.env.SECRET_MASTER_KEY; if (!envKey || envKey === FALLBACK_KEY) { + const msg = 'SECRET_MASTER_KEY 使用的是默认值,生产环境请务必设置环境变量 SECRET_MASTER_KEY'; if (process.env.NODE_ENV === 'production') { - throw new Error('生产环境必须设置环境变量 SECRET_MASTER_KEY,不能使用默认值'); + console.error(`\n🔴 严重警告: ${msg}\n`); + } else { + console.warn(`\n⚠️ 警告: ${msg}\n`); } - console.warn( - '\n⚠️ 警告: SECRET_MASTER_KEY 使用的是默认值\n' + - ' 部署到生产环境前请务必设置环境变量 SECRET_MASTER_KEY\n', - ); } const key = (envKey || FALLBACK_KEY).padEnd(32, '0').slice(0, 32); return Buffer.from(key);