2026-03-06 16:27:54 +00:00
|
|
|
import { serve } from '@hono/node-server'
|
|
|
|
|
import { app } from './app.js'
|
2026-03-07 10:42:18 +00:00
|
|
|
import { runMigrations } from './db/startup.js'
|
2026-03-08 10:33:30 +00:00
|
|
|
import { seedMockBots, seedClassicBots } from './engine/mock.js'
|
2026-03-07 11:04:32 +00:00
|
|
|
import { startBackgroundFights } from './engine/background.js'
|
2026-03-07 10:42:18 +00:00
|
|
|
|
2026-03-08 10:33:30 +00:00
|
|
|
// 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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 10:42:18 +00:00
|
|
|
// Run migrations and seed mock bots before starting the server
|
|
|
|
|
runMigrations()
|
|
|
|
|
await seedMockBots()
|
2026-03-08 10:33:30 +00:00
|
|
|
await seedClassicBots()
|
2026-03-06 16:27:54 +00:00
|
|
|
|
|
|
|
|
const port = Number(process.env.PORT) || 9100
|
|
|
|
|
|
|
|
|
|
serve({ fetch: app.fetch, port }, () => {
|
|
|
|
|
console.log(`[botfights] server listening on http://localhost:${port}`)
|
2026-03-07 11:04:32 +00:00
|
|
|
|
|
|
|
|
// Start background fight loop so the site always has fresh activity
|
|
|
|
|
startBackgroundFights()
|
2026-03-06 16:27:54 +00:00
|
|
|
})
|