refactor: extract inline middleware from index.ts into separate modules (#85)
- Extract update middleware to routes/update.ts - Extract health middleware and version logic to routes/health.ts - Extract shutdown logic to services/shutdown.ts - Extract gateway init to services/gateway-bootstrap.ts - Remove unused variables, fix duplicate app creation - Bump version to 0.4.0 index.ts: 260 lines → 80 lines Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
export function bindShutdown(server: any): void {
|
||||
let isShuttingDown = false
|
||||
|
||||
const shutdown = async (signal: string) => {
|
||||
if (isShuttingDown) return
|
||||
isShuttingDown = true
|
||||
|
||||
console.log(`\n[${signal}] shutting down...`)
|
||||
|
||||
try {
|
||||
if (server) {
|
||||
await new Promise<void>((resolve) => {
|
||||
server.close(() => {
|
||||
console.log('✓ http server closed')
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('shutdown error:', err)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
process.once('SIGUSR2', shutdown)
|
||||
process.on('SIGINT', shutdown)
|
||||
process.on('SIGTERM', shutdown)
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.error('uncaughtException:', err)
|
||||
shutdown('uncaughtException')
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
console.error('unhandledRejection:', err)
|
||||
shutdown('unhandledRejection')
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user