From 89bf052ca1c3e0c397bbaa5710519b2773b8ebb3 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 10 Mar 2026 17:19:27 -0700 Subject: [PATCH] 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 --- src/server.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/server.ts b/src/server.ts index dfa15cf..d658ec8 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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 { 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')