/** * Authenticated fetch wrapper for the Coolify API. * Ported from gitea.repo.management/electron/main.cjs:166-183 */ export async function coolifyFetch(config, apiPath, options = {}) { const base = (config.coolify?.apiUrl || '').replace(/\/$/, ''); const token = config.coolify?.apiToken || ''; const url = `${base}/api/v1${apiPath}`; const headers = { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', ...(options.headers || {}) }; const res = await fetch(url, { ...options, headers }); if (!res.ok) { const text = await res.text(); const err = new Error(`Coolify ${options.method || 'GET'} ${apiPath} failed: ${res.status} ${text}`); err.status = res.status; throw err; } const ct = res.headers.get('content-type') || ''; if (ct.includes('application/json')) return res.json(); return res.text(); }