Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions apps/server/src/api/routes/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,15 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { EXIT_CODES } from '@browseros/shared/constants/exit-codes'
import { Hono } from 'hono'
import type { Browser } from '../../browser/browser'
import { logger } from '../../lib/logger'

const HEALTH_CHECK_TIMEOUT = 5 * 60 * 1000 // 5 minutes

interface HealthDeps {
browser?: Browser
}

export function createHealthRoute(deps: HealthDeps = {}) {
let watchdogTimer: ReturnType<typeof setTimeout> | null = null

function resetWatchdog() {
if (watchdogTimer) clearTimeout(watchdogTimer)
watchdogTimer = setTimeout(() => {
logger.error(
'No health check received in 5 minutes, Chromium may be gone — exiting',
)
process.exit(EXIT_CODES.GENERAL_ERROR)
}, HEALTH_CHECK_TIMEOUT)
}

// Start the watchdog on creation
resetWatchdog()

return new Hono().get('/', (c) => {
resetWatchdog()
const cdpConnected = deps.browser?.isCdpConnected() ?? true
return c.json({ status: 'ok', cdpConnected })
})
Expand Down
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading