style: format code for better readability and consistency
Browse files- health-server.js +26 -7
health-server.js
CHANGED
|
@@ -6,7 +6,8 @@ const PORT = Number(process.env.PUBLIC_PORT || 7861);
|
|
| 6 |
const TARGET_PORT = Number(process.env.N8N_PORT || 5678);
|
| 7 |
const TARGET_HOST = "127.0.0.1";
|
| 8 |
const SYNC_STATUS_FILE = "/tmp/hugging8n-sync-status.json";
|
| 9 |
-
const CLOUDFLARE_KEEPALIVE_STATUS_FILE =
|
|
|
|
| 10 |
const startTime = Date.now();
|
| 11 |
|
| 12 |
function parseRequestUrl(url) {
|
|
@@ -33,7 +34,9 @@ function getStatus() {
|
|
| 33 |
function getKeepaliveStatus() {
|
| 34 |
try {
|
| 35 |
if (fs.existsSync(CLOUDFLARE_KEEPALIVE_STATUS_FILE)) {
|
| 36 |
-
return JSON.parse(
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
} catch {}
|
| 39 |
return null;
|
|
@@ -73,7 +76,13 @@ function toneBadge(label, tone = "neutral") {
|
|
| 73 |
return `<span class="badge ${tone}">${escapeHtml(label)}</span>`;
|
| 74 |
}
|
| 75 |
|
| 76 |
-
function renderTile({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return `<article class="tile ${tone}">
|
| 78 |
<div class="tile-head">
|
| 79 |
<span class="tile-title">${escapeHtml(title)}</span>
|
|
@@ -87,12 +96,16 @@ function renderTile({ title, value, detail = "", tone = "neutral", meta = "" })
|
|
| 87 |
|
| 88 |
function renderDashboard(data) {
|
| 89 |
const syncStatus = String(data.sync?.status || "unknown");
|
| 90 |
-
const syncTone = ["success", "restored", "synced", "configured"].includes(
|
|
|
|
|
|
|
| 91 |
? "ok"
|
| 92 |
: syncStatus === "disabled"
|
| 93 |
? "warn"
|
| 94 |
: "neutral";
|
| 95 |
-
const backupDetail = data.sync?.message
|
|
|
|
|
|
|
| 96 |
|
| 97 |
const keepaliveConfigured = data.keepalive?.configured === true;
|
| 98 |
const keepaliveStatus = String(
|
|
@@ -113,7 +126,10 @@ function renderDashboard(data) {
|
|
| 113 |
const tiles = [
|
| 114 |
renderTile({
|
| 115 |
title: "n8n Core",
|
| 116 |
-
value: toneBadge(
|
|
|
|
|
|
|
|
|
|
| 117 |
detail: `Internal Port ${TARGET_PORT}`,
|
| 118 |
tone: data.n8nReady ? "ok" : "off",
|
| 119 |
}),
|
|
@@ -134,7 +150,10 @@ function renderDashboard(data) {
|
|
| 134 |
}),
|
| 135 |
renderTile({
|
| 136 |
title: "Keep Awake",
|
| 137 |
-
value: toneBadge(
|
|
|
|
|
|
|
|
|
|
| 138 |
detail: keepAliveDetail,
|
| 139 |
tone: keepAliveTone,
|
| 140 |
}),
|
|
|
|
| 6 |
const TARGET_PORT = Number(process.env.N8N_PORT || 5678);
|
| 7 |
const TARGET_HOST = "127.0.0.1";
|
| 8 |
const SYNC_STATUS_FILE = "/tmp/hugging8n-sync-status.json";
|
| 9 |
+
const CLOUDFLARE_KEEPALIVE_STATUS_FILE =
|
| 10 |
+
"/tmp/hugging8n-cloudflare-keepalive-status.json";
|
| 11 |
const startTime = Date.now();
|
| 12 |
|
| 13 |
function parseRequestUrl(url) {
|
|
|
|
| 34 |
function getKeepaliveStatus() {
|
| 35 |
try {
|
| 36 |
if (fs.existsSync(CLOUDFLARE_KEEPALIVE_STATUS_FILE)) {
|
| 37 |
+
return JSON.parse(
|
| 38 |
+
fs.readFileSync(CLOUDFLARE_KEEPALIVE_STATUS_FILE, "utf8"),
|
| 39 |
+
);
|
| 40 |
}
|
| 41 |
} catch {}
|
| 42 |
return null;
|
|
|
|
| 76 |
return `<span class="badge ${tone}">${escapeHtml(label)}</span>`;
|
| 77 |
}
|
| 78 |
|
| 79 |
+
function renderTile({
|
| 80 |
+
title,
|
| 81 |
+
value,
|
| 82 |
+
detail = "",
|
| 83 |
+
tone = "neutral",
|
| 84 |
+
meta = "",
|
| 85 |
+
}) {
|
| 86 |
return `<article class="tile ${tone}">
|
| 87 |
<div class="tile-head">
|
| 88 |
<span class="tile-title">${escapeHtml(title)}</span>
|
|
|
|
| 96 |
|
| 97 |
function renderDashboard(data) {
|
| 98 |
const syncStatus = String(data.sync?.status || "unknown");
|
| 99 |
+
const syncTone = ["success", "restored", "synced", "configured"].includes(
|
| 100 |
+
syncStatus,
|
| 101 |
+
)
|
| 102 |
? "ok"
|
| 103 |
: syncStatus === "disabled"
|
| 104 |
? "warn"
|
| 105 |
: "neutral";
|
| 106 |
+
const backupDetail = data.sync?.message
|
| 107 |
+
? escapeHtml(data.sync.message)
|
| 108 |
+
: "No status yet";
|
| 109 |
|
| 110 |
const keepaliveConfigured = data.keepalive?.configured === true;
|
| 111 |
const keepaliveStatus = String(
|
|
|
|
| 126 |
const tiles = [
|
| 127 |
renderTile({
|
| 128 |
title: "n8n Core",
|
| 129 |
+
value: toneBadge(
|
| 130 |
+
data.n8nReady ? "Online" : "Offline",
|
| 131 |
+
data.n8nReady ? "ok" : "off",
|
| 132 |
+
),
|
| 133 |
detail: `Internal Port ${TARGET_PORT}`,
|
| 134 |
tone: data.n8nReady ? "ok" : "off",
|
| 135 |
}),
|
|
|
|
| 150 |
}),
|
| 151 |
renderTile({
|
| 152 |
title: "Keep Awake",
|
| 153 |
+
value: toneBadge(
|
| 154 |
+
keepaliveConfigured ? "CF Cron" : keepaliveStatus.toUpperCase(),
|
| 155 |
+
keepAliveTone,
|
| 156 |
+
),
|
| 157 |
detail: keepAliveDetail,
|
| 158 |
tone: keepAliveTone,
|
| 159 |
}),
|