anurag008w commited on
Commit
78eaac4
·
1 Parent(s): 3f3cffe

Update Jupyter API endpoint and enhance error handling

Browse files
Files changed (1) hide show
  1. health-server.js +7 -3
health-server.js CHANGED
@@ -302,7 +302,7 @@ const server = http.createServer(async (req, res) => {
302
  if (pathname === "/status") {
303
  const [gatewayReady, jupyterReady] = await Promise.all([
304
  probePort(GATEWAY_HOST, GATEWAY_PORT, "/health"),
305
- JUPYTER_ENABLED ? probePort(JUPYTER_HOST, JUPYTER_PORT, `${JUPYTER_BASE}/api`) : Promise.resolve(false),
306
  ]);
307
  res.writeHead(200, { "Content-Type": "application/json" });
308
  return res.end(JSON.stringify({ model: LLM_MODEL, uptime: formatUptime(Date.now() - startTime), gatewayReady, jupyterReady, sync: getSyncStatus(), whatsapp: readGuardianStatus(), keepalive: getKeepaliveStatus() }));
@@ -316,7 +316,7 @@ const server = http.createServer(async (req, res) => {
316
  if (pathname === "/" || pathname === "/dashboard") {
317
  const [gatewayReady, jupyterReady] = await Promise.all([
318
  probePort(GATEWAY_HOST, GATEWAY_PORT, "/health"),
319
- JUPYTER_ENABLED ? probePort(JUPYTER_HOST, JUPYTER_PORT, `${JUPYTER_BASE}/api`) : Promise.resolve(false),
320
  ]);
321
  res.writeHead(200, { "Content-Type": "text/html" });
322
  return res.end(renderDashboard({ uptimeHuman: formatUptime(Date.now() - startTime), gatewayReady, jupyterReady, sync: getSyncStatus(), whatsapp: readGuardianStatus(), keepalive: getKeepaliveStatus() }));
@@ -377,11 +377,15 @@ server.on("upgrade", (req, socket, head) => {
377
  if (head && head.length) ps.write(head);
378
  ps.pipe(socket).pipe(ps);
379
  });
380
- ps.on("error", () => socket.destroy());
 
 
 
381
  });
382
 
383
  server.timeout = 0;
384
  server.keepAliveTimeout = 65000;
 
385
  server.listen(PORT, "0.0.0.0", () =>
386
  console.log(`🦞 HuggingClaw :${PORT} → Gateway :${GATEWAY_PORT}${JUPYTER_ENABLED ? ` | Terminal :${JUPYTER_PORT} at ${JUPYTER_BASE}/` : " | Terminal disabled"}`),
387
  );
 
302
  if (pathname === "/status") {
303
  const [gatewayReady, jupyterReady] = await Promise.all([
304
  probePort(GATEWAY_HOST, GATEWAY_PORT, "/health"),
305
+ JUPYTER_ENABLED ? probePort(JUPYTER_HOST, JUPYTER_PORT, `${JUPYTER_BASE}/api/status`) : Promise.resolve(false),
306
  ]);
307
  res.writeHead(200, { "Content-Type": "application/json" });
308
  return res.end(JSON.stringify({ model: LLM_MODEL, uptime: formatUptime(Date.now() - startTime), gatewayReady, jupyterReady, sync: getSyncStatus(), whatsapp: readGuardianStatus(), keepalive: getKeepaliveStatus() }));
 
316
  if (pathname === "/" || pathname === "/dashboard") {
317
  const [gatewayReady, jupyterReady] = await Promise.all([
318
  probePort(GATEWAY_HOST, GATEWAY_PORT, "/health"),
319
+ JUPYTER_ENABLED ? probePort(JUPYTER_HOST, JUPYTER_PORT, `${JUPYTER_BASE}/api/status`) : Promise.resolve(false),
320
  ]);
321
  res.writeHead(200, { "Content-Type": "text/html" });
322
  return res.end(renderDashboard({ uptimeHuman: formatUptime(Date.now() - startTime), gatewayReady, jupyterReady, sync: getSyncStatus(), whatsapp: readGuardianStatus(), keepalive: getKeepaliveStatus() }));
 
377
  if (head && head.length) ps.write(head);
378
  ps.pipe(socket).pipe(ps);
379
  });
380
+ ps.on("error", () => socket.destroy());
381
+ ps.on("close", () => socket.destroy());
382
+ socket.on("error", () => ps.destroy());
383
+ socket.on("close", () => ps.destroy());
384
  });
385
 
386
  server.timeout = 0;
387
  server.keepAliveTimeout = 65000;
388
+ server.on("error", (err) => console.error(`[health-server] Server error:`, err));
389
  server.listen(PORT, "0.0.0.0", () =>
390
  console.log(`🦞 HuggingClaw :${PORT} → Gateway :${GATEWAY_PORT}${JUPYTER_ENABLED ? ` | Terminal :${JUPYTER_PORT} at ${JUPYTER_BASE}/` : " | Terminal disabled"}`),
391
  );