Files
webshop/shop/app/api/cron/sync-companies/route.ts
DanielS d5593900fb
All checks were successful
Staging Build / build (push) Successful in 2m57s
feat(cron): add automated sync endpoint and vercel cron configuration for partners
2026-07-15 00:30:13 +02:00

26 lines
871 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { syncCompaniesFromLicServer } from '@/lib/actions/companies'
export const dynamic = 'force-dynamic'
export async function GET(req: NextRequest) {
// Check authorization header
const authHeader = req.headers.get('authorization')
const cronSecret = process.env.CRON_SECRET
// Secure the cron endpoint in production
if (process.env.NODE_ENV === 'production' && cronSecret) {
if (authHeader !== `Bearer ${cronSecret}`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
}
try {
const res = await syncCompaniesFromLicServer()
return NextResponse.json({ success: true, count: res.count })
} catch (err: any) {
console.error('[cron] Sync failed:', err)
return NextResponse.json({ error: err.message || 'Sync failed' }, { status: 500 })
}
}