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:43:30 +00:00
|
|
|
// Production env validation — warn but don't crash (wallet features degrade gracefully)
|
2026-03-08 10:33:30 +00:00
|
|
|
if (process.env.NODE_ENV === 'production') {
|
2026-03-08 10:43:30 +00:00
|
|
|
const walletVars = ['BOTFIGHTS_NWC_URL', 'BOTFIGHTS_WALLET_ENCRYPTION_KEY']
|
|
|
|
|
const missing = walletVars.filter(k => !process.env[k])
|
2026-03-08 10:33:30 +00:00
|
|
|
if (missing.length > 0) {
|
2026-03-08 10:43:30 +00:00
|
|
|
console.warn(`[botfights] WARNING: Missing env vars: ${missing.join(', ')} — wallet/payment features disabled`)
|
2026-03-08 10:33:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
})
|