diff --git a/ai-server/index.mjs b/ai-server/index.mjs index e359516..8b6ccb9 100644 --- a/ai-server/index.mjs +++ b/ai-server/index.mjs @@ -269,6 +269,13 @@ function parseBody(req) { }) } +function checkPort(http, host, port, timeout) { + return new Promise((resolve, reject) => { + const r = http.get(`http://${host}:${port}`, { timeout }, (res) => { res.resume(); resolve() }) + r.on("error", reject) + }) +} + function parseURL(req) { const url = new URL(req.url, `http://${req.headers.host || "localhost"}`) return { pathname: url.pathname, searchParams: url.searchParams } @@ -309,27 +316,23 @@ const server = http.createServer(async (req, res) => { } // GET /status — combined health of all services - // Used by the splash page to check if AI, Scraper, and Frontend are ready. - // Polls each service internally to avoid cross-origin CORS issues. + // Used by the splash page to check if AI and Frontend are ready. + // Scraper is no longer part of dev:start so it's always reported ready. if (req.method === "GET" && pathname === "/status") { const { default: http } = await import("http") - const results = { ai: true } - // Check scraper (port 3008) + const results = { ai: true, scraper: true } + // Check frontend (port 3006) — try localhost, fallback to 127.0.0.1 try { - await new Promise((resolve, reject) => { - const r = http.get("http://127.0.0.1:3008/health", { timeout: 3000 }, (res) => { res.resume(); resolve() }) - r.on("error", reject) - }) - results.scraper = true - } catch { results.scraper = false } - // Check frontend (port 3006) - try { - await new Promise((resolve, reject) => { - const r = http.get("http://127.0.0.1:3006", { timeout: 3000 }, (res) => { res.resume(); resolve() }) - r.on("error", reject) - }) + await checkPort(http, "localhost", 3006, 2000) results.frontend = true - } catch { results.frontend = false } + } catch { + try { + await checkPort(http, "127.0.0.1", 3006, 2000) + results.frontend = true + } catch { + results.frontend = false + } + } return sendJSON(res, 200, results) }