Files
botfights/server/src/index.ts
T

30 lines
994 B
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
if (process.env.NODE_ENV === 'production') {
const required = ['BOTFIGHTS_NWC_URL', 'BOTFIGHTS_WALLET_ENCRYPTION_KEY']
const missing = required.filter(k => !process.env[k])
if (missing.length > 0) {
console.error(`[FATAL] Missing required env vars for production: ${missing.join(', ')}`)
process.exit(1)
}
}
// 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()
})