fix(docker): add dedicated health endpoint for container healthcheck (#1147) (#1355)

This commit is contained in:
azizur100389
2026-05-05 21:40:32 +01:00
committed by GitHub
parent e60e62f193
commit 8fc32e6af9
3 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ services:
- ${WORKSPACE_DIR:-./workspace}:/workspace:ro
restart: unless-stopped
healthcheck:
test: ['CMD', 'curl', '-fsSI', 'http://localhost:4747/api/heartbeat']
test: ['CMD', 'curl', '-f', 'http://localhost:4747/api/health']
interval: 30s
timeout: 5s
retries: 3
+8
View File
@@ -183,6 +183,7 @@ a.ext:hover{text-decoration:underline}
<div class="section-title">Endpoints</div>
<p class="endpoint"><a href="/api/info">/api/info</a> <span style="color:#5a5a70">— Server version &amp; context</span></p>
<p class="endpoint"><a href="/api/repos">/api/repos</a> <span style="color:#5a5a70">— Indexed repositories</span></p>
<p class="endpoint"><code>/api/health</code> <span style="color:#5a5a70">— Docker/orchestrator healthcheck</span></p>
<p class="endpoint"><code>/api/heartbeat</code> <span style="color:#5a5a70">— SSE heartbeat</span></p>
<p class="endpoint"><code>/api/graph</code> <code>/api/query</code> <code>/api/search</code> <span style="color:#5a5a70">— Data</span></p>
<p class="endpoint"><code>/api/mcp</code> <span style="color:#5a5a70">— MCP over StreamableHTTP</span></p>
@@ -777,6 +778,13 @@ export const createServer = async (port: number, host: string = '127.0.0.1') =>
return found;
};
// Lightweight healthcheck for Docker/orchestrator probes (#1147).
// Returns immediately so container managers do not confuse a long-lived
// SSE stream with an unhealthy server.
app.get('/api/health', (_req, res) => {
res.json({ status: 'ok' });
});
// SSE heartbeat — clients connect to detect server liveness instantly.
// When the server shuts down, the TCP connection drops and the client's
// EventSource fires onerror immediately (no polling delay).
+4
View File
@@ -242,6 +242,10 @@ describe('production routes — rate-limit middleware wiring', () => {
expect(apiSource).toMatch(/app\.get\(SPA_FALLBACK_REGEX,\s*createRouteLimiter\(/);
});
it('GET /api/health is registered (Docker healthcheck, #1147)', () => {
expect(apiSource).toMatch(/app\.get\('\/api\/health',\s*\(_req,\s*res\)\s*=>/);
});
it('createServer wires trust proxy to loopback/linklocal/uniquelocal', () => {
expect(apiSource).toMatch(
/app\.set\(\s*'trust proxy'\s*,\s*'loopback,\s*linklocal,\s*uniquelocal'\s*\)/,