diff --git a/dashcaddy-api/src/app.js b/dashcaddy-api/src/app.js index 97b760b..ada8844 100644 --- a/dashcaddy-api/src/app.js +++ b/dashcaddy-api/src/app.js @@ -487,25 +487,48 @@ async function createApp() { statusCode = await makeRequest('GET'); } } catch { - const fallbackUrl = `https://${config.buildDomain(id)}`; - const fp = new URL(fallbackUrl); - statusCode = await new Promise((resolve, reject) => { - const fReq = https.request({ - hostname: fp.hostname, - port: 443, - path: '/', - method: 'GET', - timeout: 5000, - agent: httpsAgent, - headers: { 'User-Agent': APP.USER_AGENTS.PROBE } - }, (fRes) => { - fRes.resume(); - resolve(fRes.statusCode); - }); - fReq.on('error', reject); - fReq.on('timeout', () => { fReq.destroy(); reject(new Error('Timeout')); }); - fReq.end(); - }); + // Direct probe failed — try Pylon relay if configured + const pylonConfig = config.siteConfig?.pylon; + if (pylonConfig?.url) { + try { + const pylonUrl = `${pylonConfig.url}/probe?url=${encodeURIComponent(url)}`; + const headers = { 'User-Agent': APP.USER_AGENTS.PROBE }; + if (pylonConfig.key) headers['x-pylon-key'] = pylonConfig.key; + const controller = new AbortController(); + const pylonTimeout = setTimeout(() => controller.abort(), 8000); + const pylonRes = await fetchT(pylonUrl, { method: 'GET', signal: controller.signal, headers }); + clearTimeout(pylonTimeout); + if (pylonRes.ok) { + const data = await pylonRes.json(); + statusCode = data.statusCode || 502; + } + } catch { + // Pylon also failed — fall through to domain fallback + } + } + + // Domain-based fallback (last resort) + if (!statusCode) { + const fallbackUrl = `https://${config.buildDomain(id)}`; + const fp = new URL(fallbackUrl); + statusCode = await new Promise((resolve, reject) => { + const fReq = https.request({ + hostname: fp.hostname, + port: 443, + path: '/', + method: 'GET', + timeout: 5000, + agent: httpsAgent, + headers: { 'User-Agent': APP.USER_AGENTS.PROBE } + }, (fRes) => { + fRes.resume(); + resolve(fRes.statusCode); + }); + fReq.on('error', reject); + fReq.on('timeout', () => { fReq.destroy(); reject(new Error('Timeout')); }); + fReq.end(); + }).catch(() => 502); + } } res.status(statusCode).send();