claude-cortex 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dashboard/package.json
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Ensures the API server is running before starting the dashboard.
|
|
4
|
+
* Automatically spawns the API if it's not reachable.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { dirname, join } from 'path';
|
|
10
|
+
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const rootDir = join(__dirname, '..', '..');
|
|
13
|
+
|
|
14
|
+
const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
|
|
15
|
+
const HEALTH_ENDPOINT = `${API_URL}/api/health`;
|
|
16
|
+
const MAX_WAIT_MS = 10000;
|
|
17
|
+
const POLL_INTERVAL_MS = 500;
|
|
18
|
+
|
|
19
|
+
async function checkApiHealth() {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(HEALTH_ENDPOINT, {
|
|
22
|
+
signal: AbortSignal.timeout(2000)
|
|
23
|
+
});
|
|
24
|
+
return response.ok;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function waitForApi(timeoutMs) {
|
|
31
|
+
const start = Date.now();
|
|
32
|
+
while (Date.now() - start < timeoutMs) {
|
|
33
|
+
if (await checkApiHealth()) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
await new Promise(r => setTimeout(r, POLL_INTERVAL_MS));
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function main() {
|
|
42
|
+
console.log('[Dashboard] Checking if API server is running...');
|
|
43
|
+
|
|
44
|
+
if (await checkApiHealth()) {
|
|
45
|
+
console.log('[Dashboard] API server is already running ✓');
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log('[Dashboard] API server not detected, starting it...');
|
|
50
|
+
|
|
51
|
+
// Spawn API server in background (fully detached)
|
|
52
|
+
// Using 'ignore' for all stdio to prevent SIGPIPE when parent exits
|
|
53
|
+
const apiProcess = spawn('npm', ['run', 'dev:api'], {
|
|
54
|
+
cwd: rootDir,
|
|
55
|
+
detached: true,
|
|
56
|
+
stdio: 'ignore',
|
|
57
|
+
shell: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Fully detach - allow parent to exit without killing child
|
|
61
|
+
apiProcess.unref();
|
|
62
|
+
|
|
63
|
+
// Wait for API to be ready
|
|
64
|
+
console.log('[Dashboard] Waiting for API server to be ready...');
|
|
65
|
+
const ready = await waitForApi(MAX_WAIT_MS);
|
|
66
|
+
|
|
67
|
+
if (ready) {
|
|
68
|
+
console.log('[Dashboard] API server is ready ✓');
|
|
69
|
+
process.exit(0);
|
|
70
|
+
} else {
|
|
71
|
+
console.error('[Dashboard] API server failed to start within timeout');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main();
|