const base = process.env.CRON_BASE ?? `http://127.0.0.1:${process.env.PORT ?? 4700}` const secret = process.env.CRON_SECRET?.trim() if (!secret) { console.error('[cron] CRON_SECRET fehlt') process.exit(1) } const tasks = process.argv.slice(2) const paths = tasks.length > 0 ? tasks : ['/api/v1/publish-due', '/api/v1/weekly-report'] let failed = false for (const path of paths) { try { const response = await fetch(`${base}${path}`, { method: 'POST', headers: { authorization: `Bearer ${secret}` }, }) const body = await response.text() console.log(`[cron] ${path} ${response.status} ${body}`) if (!response.ok) { failed = true } } catch (error) { console.error(`[cron] ${path} fehlgeschlagen`, error) failed = true } } process.exit(failed ? 1 : 0)