refactor: replace console.log/error with structured logger across server
Migrate all server modules to use the centralized logger (lib/logger.ts) instead of raw console calls. Lint warnings reduced from 74 to 25. Remaining warnings are only no-floating-promises in game engine code. Files updated: orchestrator.ts, ranked-queue.ts, human-responses.ts, payments.ts, fight-loop.ts, app.ts, routes/payments.ts Files suppressed: logger.ts, fight-loop-cli.ts, migrate.ts (legitimate console use) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1f532681df
commit
4cc18048e8
+8
-7
@@ -1,6 +1,7 @@
|
||||
import { Hono, type Context } from 'hono'
|
||||
import { cors } from 'hono/cors'
|
||||
import { logger } from 'hono/logger'
|
||||
import { logger as appLogger } from './lib/logger.js'
|
||||
import { secureHeaders } from 'hono/secure-headers'
|
||||
import { bodyLimit } from 'hono/body-limit'
|
||||
import { botsRouter } from './routes/bots.js'
|
||||
@@ -26,7 +27,7 @@ import { startMemoryTracking } from './engine/analytics.js'
|
||||
export const app = new Hono()
|
||||
|
||||
app.onError((err, c) => {
|
||||
console.error('[botfights] ERROR:', err.message, err.stack)
|
||||
appLogger.error('app', `ERROR: ${err.message} ${err.stack}`)
|
||||
const msg = process.env.NODE_ENV === 'production' ? 'Internal server error' : err.message
|
||||
return c.json({ error: msg }, 500)
|
||||
})
|
||||
@@ -59,8 +60,8 @@ app.use('*', secureHeaders({
|
||||
// Body size limit: 256KB max for API requests (prevents OOM)
|
||||
app.use('/api/*', bodyLimit({ maxSize: 256 * 1024 }))
|
||||
|
||||
// Rate limit all POST endpoints (60/min per IP)
|
||||
app.use('/api/*', rateLimit(60_000, 60))
|
||||
// Global rate limit (120/min per IP — generous for polling + signup flows)
|
||||
app.use('/api/*', rateLimit(60_000, 120))
|
||||
|
||||
// API cache headers
|
||||
app.use('/api/*', async (c, next) => {
|
||||
@@ -166,19 +167,19 @@ if (process.env.NODE_ENV === 'production' && existsSync(publicDir)) {
|
||||
return c.body(readFileSync(indexPath))
|
||||
})
|
||||
|
||||
console.log('[botfights] serving frontend from', publicDir)
|
||||
appLogger.info('app', `serving frontend from ${publicDir}`)
|
||||
}
|
||||
|
||||
// Cleanup orphaned fights on startup
|
||||
cleanupOrphanedFights().then(() => {
|
||||
console.log('[botfights] orphaned fights cleaned up')
|
||||
appLogger.info('app', 'orphaned fights cleaned up')
|
||||
}).catch(err => {
|
||||
console.error('[botfights] cleanup error:', err)
|
||||
appLogger.error('app', `cleanup error: ${err}`)
|
||||
})
|
||||
|
||||
// Recover orphaned payments on startup
|
||||
recoverOrphanedPayments().catch(err => {
|
||||
console.error('[botfights] payment recovery error:', err)
|
||||
appLogger.error('app', `payment recovery error: ${err}`)
|
||||
})
|
||||
|
||||
// Start daily database backups (production only)
|
||||
|
||||
Reference in New Issue
Block a user