fix: defer wallet encryption key check so server starts without it

Move crypto key init from module-level throw to lazy getKey() — only
errors when encrypt/decrypt are actually called. Downgrade env var
check in index.ts from fatal exit to warning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 10:43:30 +00:00
co-authored by Claude Opus 4.6
parent f6eb7d2845
commit 673961580c
2 changed files with 22 additions and 16 deletions
+4 -5
View File
@@ -4,13 +4,12 @@ import { runMigrations } from './db/startup.js'
import { seedMockBots, seedClassicBots } from './engine/mock.js'
import { startBackgroundFights } from './engine/background.js'
// Production env validation
// Production env validation — warn but don't crash (wallet features degrade gracefully)
if (process.env.NODE_ENV === 'production') {
const required = ['BOTFIGHTS_NWC_URL', 'BOTFIGHTS_WALLET_ENCRYPTION_KEY']
const missing = required.filter(k => !process.env[k])
const walletVars = ['BOTFIGHTS_NWC_URL', 'BOTFIGHTS_WALLET_ENCRYPTION_KEY']
const missing = walletVars.filter(k => !process.env[k])
if (missing.length > 0) {
console.error(`[FATAL] Missing required env vars for production: ${missing.join(', ')}`)
process.exit(1)
console.warn(`[botfights] WARNING: Missing env vars: ${missing.join(', ')} — wallet/payment features disabled`)
}
}