feat: initialize unidesk platform
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { type UniDeskConfig } from "./config";
|
||||
|
||||
async function readJson(url: string, init?: RequestInit): Promise<unknown> {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 5000);
|
||||
try {
|
||||
const res = await fetch(url, { ...init, signal: controller.signal });
|
||||
const text = await res.text();
|
||||
return { ok: res.ok, status: res.status, body: text.length > 0 ? JSON.parse(text) : null };
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
export async function debugHealth(config: UniDeskConfig): Promise<unknown> {
|
||||
return {
|
||||
core: await readJson(`http://127.0.0.1:${config.network.core.port}/health`),
|
||||
overview: await readJson(`http://127.0.0.1:${config.network.core.port}/api/overview`),
|
||||
nodes: await readJson(`http://127.0.0.1:${config.network.core.port}/api/nodes`),
|
||||
frontend: await readJson(`http://127.0.0.1:${config.network.frontend.port}/health`),
|
||||
};
|
||||
}
|
||||
|
||||
export async function debugDispatch(config: UniDeskConfig, providerId: string, command: "docker.ps" | "echo"): Promise<unknown> {
|
||||
return readJson(`http://127.0.0.1:${config.network.core.port}/api/dispatch`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ providerId, command, payload: { source: "cli-debug" } }),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user