Files
botfights/server/src/index.ts
T

29 lines
1.0 KiB
TypeScript
Raw Normal View History

import { serve } from '@hono/node-server'
import { app } from './app.js'
import { runMigrations } from './db/startup.js'
import { seedMockBots, seedClassicBots } from './engine/mock.js'
import { startBackgroundFights } from './engine/background.js'
// Production env validation — warn but don't crash (wallet features degrade gracefully)
if (process.env.NODE_ENV === 'production') {
const walletVars = ['BOTFIGHTS_NWC_URL', 'BOTFIGHTS_WALLET_ENCRYPTION_KEY']
const missing = walletVars.filter(k => !process.env[k])
if (missing.length > 0) {
console.warn(`[botfights] WARNING: Missing env vars: ${missing.join(', ')} — wallet/payment features disabled`)
}
}
// Run migrations and seed mock bots before starting the server
runMigrations()
await seedMockBots()
await seedClassicBots()
const port = Number(process.env.PORT) || 9100
serve({ fetch: app.fetch, port }, () => {
console.log(`[botfights] server listening on http://localhost:${port}`)
// Start background fight loop so the site always has fresh activity
startBackgroundFights()
})