Return 200 from /ok while Go server is still starting

Toes health-checks /ok during startup. The Go server can take a
while to become healthy (cloning system apps repo on first run),
so return 200 while the process is alive but not yet ready.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Corey Johnson 2026-03-10 17:19:27 -07:00
parent 84ce472c87
commit 89bf052ca1

View File

@ -7,6 +7,7 @@ const PORT = Number(process.env.PORT) || 3000
const SOCKET_PATH = DATA_DIR ? join(DATA_DIR, 'tronbyt.sock') : ''
const BIN_DIR = join(import.meta.dir, '..', 'bin')
let goHealthy = false
let goProcess: Subprocess | undefined
interface WsData {
@ -22,6 +23,7 @@ function proxyFetch(req: Request): Promise<Response> | Response {
const url = new URL(req.url)
if (url.pathname === '/ok') {
if (!goHealthy) return new Response('starting', { status: goProcess ? 200 : 503 })
return fetch('http://localhost/health', { unix: SOCKET_PATH })
.then((r) => (r.ok ? new Response('ok') : new Response('unhealthy', { status: 503 })))
.catch(() => new Response('unhealthy', { status: 503 }))
@ -176,10 +178,12 @@ async function spawnGoServer() {
goProcess.exited.then((code) => {
console.log(`Tronbyt server exited with code ${code}`)
goHealthy = false
goProcess = undefined
})
if (await waitForHealthy()) {
goHealthy = true
console.log('Tronbyt server is healthy')
} else {
console.error('Tronbyt server failed to become healthy')