mirror your GitHub repos to tangled.org automatically
1/**
2 * Trigger the worker tick endpoint locally.
3 *
4 * Reads `NUXT_CRON_SECRET` from `.env` (loaded by Node's --env-file when run
5 * via `pnpm jobs:tick`) and POSTs to /api/jobs/run with the matching
6 * `Authorization: Bearer …` header.
7 *
8 * In production, Vercel Cron does this automatically every minute; this
9 * script is the local equivalent.
10 */
11
12import process from 'node:process'
13
14const url = process.env.JOBS_TICK_URL ?? 'http://127.0.0.1:3000/api/jobs/run'
15const secret = process.env.NUXT_CRON_SECRET
16
17if (!secret) {
18 console.error('NUXT_CRON_SECRET not set; copy from .env or run `pnpm gen:cron-secret`')
19 process.exit(1)
20}
21
22const response = await fetch(url, {
23 method: 'POST',
24 headers: { authorization: `Bearer ${secret}` },
25})
26
27const body = await response.text()
28if (!response.ok) {
29 console.error(`worker tick failed with ${response.status}: ${body}`)
30 process.exit(1)
31}
32
33console.log(body)