Initial 智念AIGC platform
This commit is contained in:
26
scripts/health-check.mjs
Normal file
26
scripts/health-check.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
const port = process.env.PORT || process.env.NIANXX_PLAY_PORT || '3000';
|
||||
const hostname = process.env.HOSTNAME || '127.0.0.1';
|
||||
const baseUrl = process.env.NIANXXPLAY_PUBLIC_BASE_URL || `http://${hostname}:${port}`;
|
||||
const healthUrl = new URL('/api/health', baseUrl).toString();
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 3000);
|
||||
|
||||
try {
|
||||
const response = await fetch(healthUrl, { signal: controller.signal });
|
||||
const text = await response.text();
|
||||
if (!response.ok) {
|
||||
console.error(`[health] ${response.status} ${response.statusText}: ${text}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const payload = JSON.parse(text);
|
||||
console.log(JSON.stringify(payload, null, 2));
|
||||
if (payload?.appId !== 'zhinian-web-studio' || !payload?.ok) {
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[health] Failed to reach ${healthUrl}: ${error instanceof Error ? error.message : String(error)}`);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
Reference in New Issue
Block a user