From 88bf83ef3b321d5ebac5d86f192d6d0980adc13c Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 9 Nov 2025 21:56:06 +0000 Subject: [PATCH] Make Discord bot health URL configurable with environment variable cgen-5aa696890b9c427cae6cc113d20faa13 --- server/index.ts | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/server/index.ts b/server/index.ts index 2049cc10..fc4f5822 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1424,19 +1424,43 @@ export function createServer() { // Discord Bot Health Check (proxy to avoid CSP issues) app.get("/api/discord/bot-health", async (req, res) => { try { - const botHealthUrl = "https://aethex.railway.internal:8044/health"; + // Try multiple bot health URLs in order of preference + const botHealthUrls = [ + process.env.DISCORD_BOT_HEALTH_URL, + "http://localhost:3000/health", + "https://aethex.railway.internal:3000/health", + "https://aethex.railway.internal:8044/health", // Fallback to old Railway URL + ].filter(Boolean) as string[]; - const response = await fetch(botHealthUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }); + let lastError: Error | null = null; + let response: Response | null = null; - if (!response.ok) { - return res.status(response.status).json({ + for (const url of botHealthUrls) { + try { + console.log(`[Discord Bot Health] Trying ${url}...`); + response = await fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + timeout: 5000, + }); + + if (response.ok) { + console.log(`[Discord Bot Health] Success from ${url}`); + break; + } + } catch (err) { + lastError = err instanceof Error ? err : new Error(String(err)); + console.warn(`[Discord Bot Health] Failed to reach ${url}: ${lastError.message}`); + continue; + } + } + + if (!response?.ok) { + return res.status(503).json({ status: "offline", - error: `HTTP ${response.status}: Failed to reach bot`, + error: `Could not reach bot health endpoint. Last error: ${lastError?.message || "Unknown error"}`, }); }