fix: expose claudeqq adapter health fields
This commit is contained in:
@@ -11,6 +11,16 @@ const deployRequestedCommit = process.env.UNIDESK_DEPLOY_REQUESTED_COMMIT || dep
|
||||
const deployRepo = process.env.UNIDESK_DEPLOY_REPO || "";
|
||||
const serviceId = process.env.UNIDESK_DEPLOY_SERVICE_ID || "claudeqq";
|
||||
const startedAt = new Date().toISOString();
|
||||
const endpoints = [
|
||||
"/health",
|
||||
"/logs",
|
||||
"/api/push/text",
|
||||
"/api/send/text",
|
||||
"/api/server/status",
|
||||
"/api/napcat/login",
|
||||
"/api/events/recent",
|
||||
"/api/events/subscriptions",
|
||||
];
|
||||
|
||||
const child = spawn("node", ["dist/index.js", "--max-restarts", "0"], {
|
||||
cwd: process.env.CLAUDEQQ_SERVER_CWD || process.cwd(),
|
||||
@@ -68,6 +78,16 @@ function upstreamFetch(path, method = "GET") {
|
||||
});
|
||||
}
|
||||
|
||||
async function upstreamJson(path) {
|
||||
const response = await upstreamFetch(path);
|
||||
if (!response.ok || typeof response.body !== "string") return null;
|
||||
try {
|
||||
return JSON.parse(response.body);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function proxy(req, res, path, bodyOverride) {
|
||||
const incomingBody = bodyOverride === undefined ? await readBody(req) : Buffer.from(JSON.stringify(bodyOverride));
|
||||
const headers = { ...req.headers };
|
||||
@@ -98,11 +118,27 @@ const server = http.createServer(async (req, res) => {
|
||||
const url = new URL(req.url || "/", `http://${req.headers.host || "localhost"}`);
|
||||
if (url.pathname === "/health") {
|
||||
const upstreamHealth = await upstreamFetch("/health");
|
||||
const status = await upstreamJson("/api/server/status");
|
||||
const statusNapcat = status && typeof status === "object" ? status.napcat || {} : {};
|
||||
const httpConnected = statusNapcat.httpConnected === true;
|
||||
const wsConnected = statusNapcat.wsConnected === true;
|
||||
const connected = statusNapcat.connected === true || (httpConnected && wsConnected);
|
||||
json(res, upstreamHealth.ok ? 200 : 503, {
|
||||
ok: upstreamHealth.ok,
|
||||
service: serviceId,
|
||||
pureBackend: true,
|
||||
napcat: { containerized: true },
|
||||
endpoints,
|
||||
napcat: {
|
||||
containerized: true,
|
||||
connected,
|
||||
httpConnected,
|
||||
wsConnected,
|
||||
loginState: connected ? "logged_in" : "unknown",
|
||||
httpHost: statusNapcat.httpHost || upstreamHost,
|
||||
httpPort: statusNapcat.httpPort || 3000,
|
||||
wsHost: statusNapcat.wsHost || upstreamHost,
|
||||
wsPort: statusNapcat.wsPort || 3001,
|
||||
},
|
||||
adapter: "unidesk-claudeqq-adapter",
|
||||
startedAt,
|
||||
upstream: { url: `http://${upstreamHost}:${upstreamPort}`, ok: upstreamHealth.ok, status: upstreamHealth.status },
|
||||
|
||||
Reference in New Issue
Block a user