diff --git a/server.js b/server.js index 9587c0a..c84df90 100644 --- a/server.js +++ b/server.js @@ -243,7 +243,7 @@ const AUTH = (() => { const opts = { method: m, hostname: u.hostname, port: u.port || (u.protocol === 'https:' ? 443 : 80), path: u.pathname + u.search, headers: { 'Content-Type': 'application/json', Accept: 'application/json', ...(c.apiKey ? { 'X-Api-Key': c.apiKey } : {}) }, - timeout: 8000 }; + timeout: 15000 }; const rq = mod.request(opts, rs => { let b = ''; rs.on('data', d2 => b += d2); @@ -260,10 +260,13 @@ const AUTH = (() => { async function heartbeat() { const c = cfg(); if (!c.apiKey || !c.projectId) return null; - const r = await request('POST', '/public/installations/check-update', { - project_id: c.projectId, machine_id: machineId(), - client_version: c.version, device_info: 'Docker ' + (process.env.HOSTNAME || 'container') - }); + const body = { project_id: c.projectId, machine_id: machineId(), + client_version: c.version, device_info: 'Docker ' + (process.env.HOSTNAME || 'container') }; + let r = await request('POST', '/public/installations/check-update', body); + if (!r) { // FRP 隧道冷启动偶发超时,重试一次 + await new Promise(x => setTimeout(x, 2500)); + r = await request('POST', '/public/installations/check-update', body); + } if (r && r.code === 200 && r.data) { meta = r.data; metaAt = Date.now(); } return (r && r.code === 200) ? r.data : null; }