fix: support ts backend core cli probes
This commit is contained in:
+15
-2
@@ -915,8 +915,21 @@ function runPsql(config: UniDeskConfig, sql: string): { ok: boolean; stdout: str
|
||||
}
|
||||
|
||||
function dockerCoreJson(path: string, init?: { method?: string; body?: unknown }): unknown {
|
||||
const command = ["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", `http://127.0.0.1:8080${path}`, "--method", init?.method ?? "GET"];
|
||||
if (init?.body !== undefined) command.push("--body-json", JSON.stringify(init.body));
|
||||
const method = init?.method ?? "GET";
|
||||
const body = init?.body === undefined ? "" : JSON.stringify(init.body);
|
||||
const url = `http://127.0.0.1:8080${path}`;
|
||||
const script = [
|
||||
"set -euo pipefail",
|
||||
"if command -v backend-core >/dev/null 2>&1; then",
|
||||
` exec backend-core --fetch-json ${shellQuote(url)} --method ${shellQuote(method)}${body.length > 0 ? ` --body-json ${shellQuote(body)}` : ""}`,
|
||||
"fi",
|
||||
`url=${shellQuote(url)}`,
|
||||
`method=${shellQuote(method)}`,
|
||||
`body=${shellQuote(body)}`,
|
||||
"export url method body",
|
||||
"bun -e 'const url=process.env.url; const method=process.env.method; const body=process.env.body; fetch(url,{method,body:body?body:undefined,headers:body?{\"content-type\":\"application/json\"}:undefined}).then(async r=>{const text=await r.text(); console.log(JSON.stringify({ok:r.ok,status:r.status,body:text?JSON.parse(text):null})); process.exit(r.ok?0:1);}).catch(e=>{console.error(e); process.exit(1)})'",
|
||||
].join("\n");
|
||||
const command = ["docker", "exec", "unidesk-backend-core", "sh", "-lc", script];
|
||||
const result = runCommand(command, repoRoot);
|
||||
if (result.exitCode !== 0) return { ok: false, exitCode: result.exitCode, stdout: result.stdout.slice(-1200), stderr: result.stderr.slice(-1200) };
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user