deckhearth/pages/api/cron/sync-catalog.js
Randall Stillwell 1cc2e28423 Migrate Deck Hearth off Vercel/Neon to homelab Dokploy stack.
Replace @vercel/postgres, Blob, and Upstash with lib/sql.js, MinIO object
storage, and CT 102 Redis rate limits. Add Dockerfile for Dokploy deploy,
homelab runbooks, Neon data-copy helper, and point CI smoke/visual at the
homelab URL instead of Vercel previews.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 09:32:13 -05:00

41 lines
1.2 KiB
JavaScript

import { runUnifiedCatalogSync } from '../../../lib/card-import/sync-catalog.js';
function authorizeCron(req) {
const secret = process.env.CRON_SECRET;
if (!secret) {
if (process.env.NODE_ENV === 'production') {
return { ok: false, status: 503, error: 'CRON_SECRET is not configured' };
}
console.warn('[GET /api/cron/sync-catalog] CRON_SECRET unset — allowing in dev');
return { ok: true };
}
const authHeader = req.headers.authorization || '';
const token = authHeader.startsWith('Bearer ') ? authHeader.slice('Bearer '.length) : '';
if (!token || token !== secret) {
return { ok: false, status: 401, error: 'Unauthorized' };
}
return { ok: true };
}
export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
const auth = authorizeCron(req);
if (!auth.ok) {
return res.status(auth.status).json({ error: auth.error });
}
try {
const summary = await runUnifiedCatalogSync();
return res.status(200).json({ success: true, ...summary });
} catch (error) {
console.error('[GET /api/cron/sync-catalog]', error);
return res.status(500).json({ error: 'Catalog sync failed', details: error.message });
}
}